Update codes/typescript/chapter_searching/hashing_search.ts
Co-authored-by: Justin Tse <xiefahit@gmail.com>
This commit is contained in:
parent
c6f6fa0015
commit
4d542be9d4
@ -9,10 +9,10 @@ import ListNode from "../module/ListNode";
|
||||
|
||||
|
||||
/* 哈希查找(数组) */
|
||||
function hashingSearch(map: Map<number, number>, target: number) {
|
||||
function hashingSearch(map: Map<number, number>, target: number): number {
|
||||
// 哈希表的 key: 目标元素,value: 索引
|
||||
// 若哈希表中无此 key ,返回 -1
|
||||
return map.has(target) ? map.get(target) : -1;
|
||||
return map.has(target) ? map.get(target) as number : -1;
|
||||
}
|
||||
|
||||
/* 哈希查找(链表) */
|
||||
|
Loading…
x
Reference in New Issue
Block a user