Skip to content

Commit c738ffb

Browse files
committed
2293. 极大极小游戏
1 parent c73bd79 commit c738ffb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
|2032|[至少在两个数组中出现的值](https://leetcode.cn/problems/two-out-of-three/)|[JavaScript](./algorithms/two-out-of-three.js)|Easy|
180180
|2283|[判断一个数的数字计数是否等于数位的值](https://leetcode.cn/problems/check-if-number-has-equal-digit-count-and-digit-value/)|[JavaScript](./algorithms/check-if-number-has-equal-digit-count-and-digit-value.js)|Easy|
181181
|2287|[重排字符形成目标字符串](https://leetcode.cn/problems/rearrange-characters-to-make-target-string/)|[JavaScript](./algorithms/rearrange-characters-to-make-target-string.js)|Easy|
182+
|2293|[极大极小游戏](https://leetcode.cn/problems/min-max-game/)|[JavaScript](./algorithms/min-max-game.js)|Easy|
182183
|面试题 04.12|[面试题 04.12. 求和路径](https://leetcode.cn/problems/paths-with-sum-lcci/)|[JavaScript](./algorithms/paths-with-sum-lcci.js)|Medium|
183184
|面试题 02.07|[面试题 02.07. 链表相交](https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/)|[JavaScript](./algorithms/intersection-of-two-linked-lists-lcci.js)|Easy|
184185
|剑指 Offer 05. 替换空格|[剑指 Offer 05. 替换空格](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)|[JavaScript](./algorithms/ti-huan-kong-ge-lcof.js)|Easy|

algorithms/min-max-game.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var minMaxGame = function (nums) {
6+
let temp;
7+
while (nums.length !== 1) {
8+
temp = [];
9+
for (let i = 0; i < nums.length / 2; i++) {
10+
if (i % 2 === 0) {
11+
temp[i] = Math.min(nums[2 * i], nums[2 * i + 1]);
12+
} else {
13+
temp[i] = Math.max(nums[2 * i], nums[2 * i + 1]);
14+
}
15+
}
16+
nums = temp;
17+
}
18+
return nums[0];
19+
};

0 commit comments

Comments
 (0)