嗯,跟很久之前的题目很像
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
p = -1
i = 0
count = 0
while i < len(nums):
if nums[i] != 0:
p += 1
nums[p] = nums[i]
else:
count += 1
i += 1
while count:
p += 1
nums[p] = 0
count -= 1
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
p = -1
i = 0
while i < len(nums):
if nums[i] != 0:
p += 1
nums[p] = nums[i]
i += 1
for j in range(p+1, len(nums)):
nums[j] = 0