给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
class Solution:
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
cnt = 0
for num in nums:
if num != 0:
nums[cnt] = num
cnt += 1
for ix in range(cnt,len(nums)):
nums[ix]=0
#return nums