File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
typescript/src/insertDeleteGetRandom Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -44,14 +44,19 @@ class RandomizedSet {
44
44
}
45
45
46
46
insert(val : number ): boolean {
47
- if (this .map .has (val )) return false ;
47
+ if (this .map .has (val )) {
48
+ return false ;
49
+ }
50
+
48
51
this .map .set (val , this .list .length );
49
52
this .list .push (val );
50
53
return true ;
51
54
}
52
55
53
56
remove(val : number ): boolean {
54
- if (! this .map .has (val )) return false ;
57
+ if (! this .map .has (val )) {
58
+ return false ;
59
+ }
55
60
56
61
const index = this .map .get (val ) as number ;
57
62
const lastElement = this .list [this .list .length - 1 ];
Original file line number Diff line number Diff line change @@ -8,14 +8,19 @@ export class RandomizedSet {
8
8
}
9
9
10
10
insert ( val : number ) : boolean {
11
- if ( this . map . has ( val ) ) return false ;
11
+ if ( this . map . has ( val ) ) {
12
+ return false ;
13
+ }
14
+
12
15
this . map . set ( val , this . list . length ) ;
13
16
this . list . push ( val ) ;
14
17
return true ;
15
18
}
16
19
17
20
remove ( val : number ) : boolean {
18
- if ( ! this . map . has ( val ) ) return false ;
21
+ if ( ! this . map . has ( val ) ) {
22
+ return false ;
23
+ }
19
24
20
25
const index = this . map . get ( val ) as number ;
21
26
const lastElement = this . list [ this . list . length - 1 ] ;
You can’t perform that action at this time.
0 commit comments