my python codes


  • 0
    A
    class Solution(object):
        def moveZeroes(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            length = len(nums)
            zeroCount = 0
            lastIndex = 0
            for i in range(length):
                if nums[i] == 0:
                    zeroCount += 1
                else:
                    nums[lastIndex] = nums[i]
                    lastIndex += 1
            for i in range(length-zeroCount, length):
                nums[i] = 0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.