Leetcode【283】Move Zeroes (Python版)

class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: None Do not return anything, modify nums in-place instead.
        """
        index = 0
        for i in nums:
            if i != 0:
                nums[index] = i
                index += 1
        while index < len(nums):
            nums[index] = 0
            index += 1
        return nums

 

你可能感兴趣的:(leetcode,python,python,leetcode)