2974.最小数字游戏
链接:2974.最小数字游戏
难度:Easy
标签:数组、排序、模拟、堆(优先队列)
简介:返回结果数组 arr 。
题解 1 - python
- 编辑时间:2024-07-12
- 执行用时:49ms
- 内存消耗:16.31MB
- 编程语言:python
- 解法介绍:遍历。
class Solution:
def numberGame(self, nums: List[int]) -> List[int]:
arr = []
nums.sort()
i = 0
while i < len(nums):
arr.append(nums[i + 1])
arr.append(nums[i])
i += 2
return arr