Python 实例教学_ 07_复习

Yake1965 2022-11-08 03:35:12 阅读数:964

Python实例复习教学07_

6229. 对数组执行操作

class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
n, left = len(nums), 0
for i in range(n):
if i + 1 < n and nums[i] == nums[i + 1]:
nums[i], nums[i + 1] = nums[i] * 2, 0
if nums[i]:
nums[i], nums[left] = nums[left], nums[i]
left += 1
return nums
版权声明:本文为[Yake1965]所创,转载请带上原文链接,感谢。 https://blog.csdn.net/weixin_43955170/article/details/127724919