Skip to content

Commit 3563e39

Browse files
authored
Merge pull request #48 from masx200/masx200-patch-2
https://leetcode.cn/problems/min-max-game/
2 parents ba452c0 + e2c2624 commit 3563e39

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode.cn/problems/min-max-game/
53+
5254
https://leetcode-cn.com/problems/wiggle-subsequence/
5355

5456
https://leetcode.cn/problems/number-of-different-subsequences-gcds/

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)