1. Hashing search and test using go

pull/91/head
chenshilong 2022-12-12 16:41:41 +08:00
parent 78901d8689
commit c5e5be07b8
2 changed files with 21 additions and 5 deletions

View File

@ -14,7 +14,6 @@ import (
func hashingSearch(m map[int]int, target int) int {
// 哈希表的 key: 目标元素value: 索引
// 若哈希表中无此 key ,返回 -1
if index, ok := m[target]; ok {
return index
} else {
@ -22,11 +21,10 @@ func hashingSearch(m map[int]int, target int) int {
}
}
/* 哈希查找(数组 */
/* 哈希查找(链表 */
func hashingSearch1(m map[int]*pkg.ListNode, target int) *pkg.ListNode {
// 哈希表的 key: 目标结点值value: 结点对象
// 若哈希表中无此 key ,返回 nil
if node, ok := m[target]; ok {
return node
} else {

View File

@ -53,7 +53,16 @@ comments: true
=== "Go"
```go title="hashing_search.go"
/* 哈希查找(数组) */
func hashingSearch(m map[int]int, target int) int {
// 哈希表的 key: 目标元素value: 索引
// 若哈希表中无此 key ,返回 -1
if index, ok := m[target]; ok {
return index
} else {
return -1
}
}
```
=== "JavaScript"
@ -121,7 +130,16 @@ comments: true
=== "Go"
```go title="hashing_search.go"
/* 哈希查找(链表) */
func hashingSearch1(m map[int]*pkg.ListNode, target int) *pkg.ListNode {
// 哈希表的 key: 目标结点值value: 结点对象
// 若哈希表中无此 key ,返回 nil
if node, ok := m[target]; ok {
return node
} else {
return nil
}
}
```
=== "JavaScript"