Update hashing_search.md
补充js和ts对应的哈希查找
This commit is contained in:
parent
36507b84a0
commit
ca88928386
@ -68,13 +68,23 @@ comments: true
|
|||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
```js title="hashing_search.js"
|
```js title="hashing_search.js"
|
||||||
|
/* 哈希查找(数组) */
|
||||||
|
function hashingSearch(map, target) {
|
||||||
|
// 哈希表的 key: 目标元素,value: 索引
|
||||||
|
// 若哈希表中无此 key ,返回 -1
|
||||||
|
return map.has(target) ? map.get(target) : -1;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "TypeScript"
|
=== "TypeScript"
|
||||||
|
|
||||||
```typescript title="hashing_search.ts"
|
```typescript title="hashing_search.ts"
|
||||||
|
/* 哈希查找(数组) */
|
||||||
|
function hashingSearch1(map: Map<number, number>, target: number) {
|
||||||
|
// 哈希表的 key: 目标元素,value: 索引
|
||||||
|
// 若哈希表中无此 key ,返回 -1
|
||||||
|
return map.has(target) ? map.get(target) : -1;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "C"
|
=== "C"
|
||||||
@ -151,13 +161,22 @@ comments: true
|
|||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
```js title="hashing_search.js"
|
```js title="hashing_search.js"
|
||||||
|
/* 哈希查找(链表) */
|
||||||
|
function hashingSearch1(map, target) {
|
||||||
|
// 哈希表的 key: 目标结点值,value: 结点对象
|
||||||
|
// 若哈希表中无此 key ,返回 null
|
||||||
|
return map.has(target) ? map.get(target) : null;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "TypeScript"
|
=== "TypeScript"
|
||||||
|
|
||||||
```typescript title="hashing_search.ts"
|
```typescript title="hashing_search.ts"
|
||||||
|
function hashingSearch1(map: Map<number, any>, target: number) {
|
||||||
|
// 哈希表的 key: 目标结点值,value: 结点对象
|
||||||
|
// 若哈希表中无此 key ,返回 null
|
||||||
|
return map.has(target) ? map.get(target) : null;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "C"
|
=== "C"
|
||||||
|
Loading…
Reference in New Issue
Block a user