File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -4,27 +4,24 @@ interface Skiplist {
4
4
erase : ( num : number ) => boolean ;
5
5
}
6
6
7
-
8
7
function Skiplist ( ) : Skiplist {
9
8
const storage = new Map < number , number > ( ) ;
10
9
11
10
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 ;
13
12
}
14
13
15
14
function add ( num : number ) : void {
16
15
storage . set ( num , 1 + ( storage . get ( num ) || 0 ) ) ;
17
16
}
18
17
19
18
function erase ( num : number ) : boolean {
19
+ if ( storage . get ( num ) === 1 ) {
20
+ storage . delete ( num ) ;
20
21
21
- if ( storage . get ( num ) === 1 ) {
22
- storage . delete ( num )
23
-
24
- return true
25
- }
22
+ return true ;
23
+ }
26
24
if ( search ( num ) ) {
27
-
28
25
storage . set ( num , - 1 + ( storage . get ( num ) || 0 ) ) ;
29
26
return true ;
30
27
} else {
@@ -34,4 +31,4 @@ return true
34
31
return { search, add, erase } ;
35
32
}
36
33
37
- export default Skiplist
34
+ export default Skiplist ;
You can’t perform that action at this time.
0 commit comments