File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed
solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,20 @@ func min(a, b int) int {
124
124
### ** TypeScript**
125
125
126
126
``` ts
127
-
127
+ function minimumCardPickup(cards : number []): number {
128
+ const n = cards .length ;
129
+ let hashMap = new Map <number , number >();
130
+ const max = Number .MAX_SAFE_INTEGER;
131
+ let ans = max ;
132
+ for (let i = 0 ; i < n ; i ++ ) {
133
+ let num = cards [i ];
134
+ if (hashMap .has (num )) {
135
+ ans = Math .min (i - hashMap .get (num ) + 1 , ans );
136
+ }
137
+ hashMap .set (num , i );
138
+ }
139
+ return ans == max ? - 1 : ans ;
140
+ };
128
141
```
129
142
130
143
### ** ...**
Original file line number Diff line number Diff line change @@ -118,7 +118,20 @@ func min(a, b int) int {
118
118
### ** TypeScript**
119
119
120
120
``` ts
121
-
121
+ function minimumCardPickup(cards : number []): number {
122
+ const n = cards .length ;
123
+ let hashMap = new Map <number , number >();
124
+ const max = Number .MAX_SAFE_INTEGER;
125
+ let ans = max ;
126
+ for (let i = 0 ; i < n ; i ++ ) {
127
+ let num = cards [i ];
128
+ if (hashMap .has (num )) {
129
+ ans = Math .min (i - hashMap .get (num ) + 1 , ans );
130
+ }
131
+ hashMap .set (num , i );
132
+ }
133
+ return ans == max ? - 1 : ans ;
134
+ };
122
135
```
123
136
124
137
### ** ...**
Original file line number Diff line number Diff line change
1
+ function minimumCardPickup ( cards : number [ ] ) : number {
2
+ const n = cards . length ;
3
+ let hashMap = new Map < number , number > ( ) ;
4
+ const max = Number . MAX_SAFE_INTEGER ;
5
+ let ans = max ;
6
+ for ( let i = 0 ; i < n ; i ++ ) {
7
+ let num = cards [ i ] ;
8
+ if ( hashMap . has ( num ) ) {
9
+ ans = Math . min ( i - hashMap . get ( num ) + 1 , ans ) ;
10
+ }
11
+ hashMap . set ( num , i ) ;
12
+ }
13
+ return ans == max ? - 1 : ans ;
14
+ } ;
You can’t perform that action at this time.
0 commit comments