Skip to content

Commit e2c2624

Browse files
authored
Create index.ts
1 parent 87c8841 commit e2c2624

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

min-max-game/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function minMaxGame(nums: number[]): number {
2+
3+
4+
5+
while (nums.length !== 1) {
6+
7+
8+
9+
const n = nums.length;
10+
11+
const newNums: number[]= new Array(Math.floor(n / 2)).fill(0).map((_,i)=>i % 2 === 0?Math.min(nums[2 * i], nums[2 * i + 1]):Math.max(nums[2 * i], nums[2 * i + 1]));
12+
13+
14+
15+
nums = newNums;
16+
17+
18+
19+
}
20+
21+
return nums[0];
22+
23+
}
24+
export default minMaxGame

0 commit comments

Comments
 (0)