File tree 3 files changed +45
-2
lines changed
solution/2200-2299/2293.Min Max Game
3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,21 @@ func min(a, b int) int {
159
159
### ** TypeScript**
160
160
161
161
``` ts
162
-
162
+ function minMaxGame(nums : number []): number {
163
+ while (nums .length > 1 ) {
164
+ let n = nums .length ;
165
+ let tmp = [];
166
+ for (let i = 0 ; i < n ; i += 2 ) {
167
+ if (i % 4 == 2 ) {
168
+ tmp .push (Math .max (nums [i ], nums [i + 1 ]));
169
+ } else {
170
+ tmp .push (Math .min (nums [i ], nums [i + 1 ]));
171
+ }
172
+ }
173
+ nums = tmp ;
174
+ }
175
+ return nums [0 ];
176
+ };
163
177
```
164
178
165
179
### ** ...**
Original file line number Diff line number Diff line change @@ -145,7 +145,21 @@ func min(a, b int) int {
145
145
### ** TypeScript**
146
146
147
147
``` ts
148
-
148
+ function minMaxGame(nums : number []): number {
149
+ while (nums .length > 1 ) {
150
+ let n = nums .length ;
151
+ let tmp = [];
152
+ for (let i = 0 ; i < n ; i += 2 ) {
153
+ if (i % 4 == 2 ) {
154
+ tmp .push (Math .max (nums [i ], nums [i + 1 ]));
155
+ } else {
156
+ tmp .push (Math .min (nums [i ], nums [i + 1 ]));
157
+ }
158
+ }
159
+ nums = tmp ;
160
+ }
161
+ return nums [0 ];
162
+ };
149
163
```
150
164
151
165
### ** ...**
Original file line number Diff line number Diff line change
1
+ function minMaxGame ( nums : number [ ] ) : number {
2
+ while ( nums . length > 1 ) {
3
+ let n = nums . length ;
4
+ let tmp = [ ] ;
5
+ for ( let i = 0 ; i < n ; i += 2 ) {
6
+ if ( i % 4 == 2 ) {
7
+ tmp . push ( Math . max ( nums [ i ] , nums [ i + 1 ] ) ) ;
8
+ } else {
9
+ tmp . push ( Math . min ( nums [ i ] , nums [ i + 1 ] ) ) ;
10
+ }
11
+ }
12
+ nums = tmp ;
13
+ }
14
+ return nums [ 0 ] ;
15
+ } ;
You can’t perform that action at this time.
0 commit comments