mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
772183705e
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
30 lines
892 B
Go
30 lines
892 B
Go
// File: hashing_search.go
|
|
// Created Time: 2022-12-12
|
|
// Author: Slone123c (274325721@qq.com)
|
|
|
|
package chapter_searching
|
|
|
|
import . "github.com/krahets/hello-algo/pkg"
|
|
|
|
/* Хеш-поиск (массив) */
|
|
func hashingSearchArray(m map[int]int, target int) int {
|
|
// key хеш-таблицы: целевой элемент, value: индекс
|
|
// Если такого key нет в хеш-таблице, вернуть -1
|
|
if index, ok := m[target]; ok {
|
|
return index
|
|
} else {
|
|
return -1
|
|
}
|
|
}
|
|
|
|
/* Хеш-поиск (связный список) */
|
|
func hashingSearchLinkedList(m map[int]*ListNode, target int) *ListNode {
|
|
// key хеш-таблицы: значение целевого узла, value: объект узла
|
|
// Если такого key нет в хеш-таблице, вернуть nil
|
|
if node, ok := m[target]; ok {
|
|
return node
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|