Skip to content

Commit 942a0e5

Browse files
committed
feat: add typescript solution to lc problem: No.2293
No.2293.Min Max Game
1 parent c5b8624 commit 942a0e5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

solution/2200-2299/2293.Min Max Game/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,21 @@ func min(a, b int) int {
159159
### **TypeScript**
160160

161161
```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+
};
163177
```
164178

165179
### **...**

solution/2200-2299/2293.Min Max Game/README_EN.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,21 @@ func min(a, b int) int {
145145
### **TypeScript**
146146

147147
```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+
};
149163
```
150164

151165
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
};

0 commit comments

Comments
 (0)