2293. Min Max Game — Daily Problem
Although it's a simple problem, it involves a recursive idea.
The approach is to continuously convert the 1D list into a 2D list for processing (this avoids index confusion caused by in-place changes), then use a flag counter to compare maximum and minimum values.
At the end, return the only remaining number — though we know it must be nums[0] by this point, we still use nums[0] to avoid warnings.
class Solution:
def minMaxGame(self, nums: List[int]) -> int:
flag = 0
while len(nums) > 1:
nums = [nums[i:i + 2] for i in range(0, len(nums), 2)]
# split into 2D
for i in range(len(nums)):
if flag % 2 == 0:
nums[i] = min(nums[i])
flag += 1
else:
nums[i] = max(nums[i])
flag += 1
return nums[0]贡献者
这篇文章有帮助吗?
最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0