1. Code formatted
This commit is contained in:
parent
c5e5be07b8
commit
bb24e8083a
@ -4,11 +4,7 @@
|
|||||||
|
|
||||||
package chapter_searching
|
package chapter_searching
|
||||||
|
|
||||||
import (
|
import . "github.com/krahets/hello-algo/pkg"
|
||||||
//"fmt"
|
|
||||||
"github.com/krahets/hello-algo/pkg"
|
|
||||||
_ "github.com/krahets/hello-algo/pkg"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* 哈希查找(数组) */
|
/* 哈希查找(数组) */
|
||||||
func hashingSearch(m map[int]int, target int) int {
|
func hashingSearch(m map[int]int, target int) int {
|
||||||
@ -22,7 +18,7 @@ func hashingSearch(m map[int]int, target int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 哈希查找(链表) */
|
/* 哈希查找(链表) */
|
||||||
func hashingSearch1(m map[int]*pkg.ListNode, target int) *pkg.ListNode {
|
func hashingSearch1(m map[int]*ListNode, target int) *ListNode {
|
||||||
// 哈希表的 key: 目标结点值,value: 结点对象
|
// 哈希表的 key: 目标结点值,value: 结点对象
|
||||||
// 若哈希表中无此 key ,返回 nil
|
// 若哈希表中无此 key ,返回 nil
|
||||||
if node, ok := m[target]; ok {
|
if node, ok := m[target]; ok {
|
||||||
|
@ -6,7 +6,7 @@ package chapter_searching
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/krahets/hello-algo/pkg"
|
. "github.com/krahets/hello-algo/pkg"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,9 +23,9 @@ func TestHashingSearch(t *testing.T) {
|
|||||||
fmt.Println("目标元素 3 的索引 = ", index)
|
fmt.Println("目标元素 3 的索引 = ", index)
|
||||||
|
|
||||||
/* 哈希查找(链表) */
|
/* 哈希查找(链表) */
|
||||||
head := pkg.ArrayToLinkedList(nums)
|
head := ArrayToLinkedList(nums)
|
||||||
// 初始化哈希表
|
// 初始化哈希表
|
||||||
m1 := make(map[int]*pkg.ListNode)
|
m1 := make(map[int]*ListNode)
|
||||||
for head != nil {
|
for head != nil {
|
||||||
m1[head.Val] = head
|
m1[head.Val] = head
|
||||||
head = head.Next
|
head = head.Next
|
||||||
|
Loading…
Reference in New Issue
Block a user