Skip to content

Commit 3b8f8a5

Browse files
committed
Update index.ts
1 parent af4c3a4 commit 3b8f8a5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

design-skiplist/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@ interface Skiplist {
44
erase: (num: number) => boolean;
55
}
66

7-
87
function Skiplist(): Skiplist {
98
const storage = new Map<number, number>();
109

1110
function search(target: number): boolean {
12-
return storage.has(target)&&(storage.get(target) || 0) > 0;
11+
return storage.has(target) && (storage.get(target) || 0) > 0;
1312
}
1413

1514
function add(num: number): void {
1615
storage.set(num, 1 + (storage.get(num) || 0));
1716
}
1817

1918
function erase(num: number): boolean {
19+
if (storage.get(num) === 1) {
20+
storage.delete(num);
2021

21-
if(storage.get(num)===1){
22-
storage.delete(num)
23-
24-
return true
25-
}
22+
return true;
23+
}
2624
if (search(num)) {
27-
2825
storage.set(num, -1 + (storage.get(num) || 0));
2926
return true;
3027
} else {
@@ -34,4 +31,4 @@ return true
3431
return { search, add, erase };
3532
}
3633

37-
export default Skiplist
34+
export default Skiplist;

0 commit comments

Comments
 (0)