Move Zeroes
Description:
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
Example
Given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].
Code:
class Solution:
"""
@param nums: an integer array
@return: nothing
"""
def moveZeroes(self, nums):
# write your code here
cnt = 0
tmp = []
for i in range(len(nums)):
if nums[i] != 0:
tmp.append(nums[i])
else:
cnt += 1
for i in range(cnt):
tmp.append(0)
nums[:] = tmp[:]