❤leetcode,python2❤给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序

232 阅读1分钟
class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        j=0
        for i in xrange(len(nums)):
            if nums[j] == 0:
                nums.append(nums.pop(j))

            else:
                j+=1