Files
hello-algo/ja/codes/go/chapter_searching/hashing_search.go
Yudong Jin 7257641e0e Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
2026-10-30 02:12:26 +08:00

30 lines
882 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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
}
}