diff --git a/README.md b/README.md index 8fd41bc3..441d6a92 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ Step 2. Add the dependency 展开查看 +https://leetcode.cn/problems/min-max-game/ + https://leetcode-cn.com/problems/wiggle-subsequence/ https://leetcode.cn/problems/number-of-different-subsequences-gcds/ diff --git a/min-max-game/index.ts b/min-max-game/index.ts new file mode 100644 index 00000000..369cbcf3 --- /dev/null +++ b/min-max-game/index.ts @@ -0,0 +1,24 @@ +function minMaxGame(nums: number[]): number { + + + + while (nums.length !== 1) { + + + + const n = nums.length; + + 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])); + + + + nums = newNums; + + + + } + + return nums[0]; + +} +export default minMaxGame