A fast and easy understand way to solve with Python.

  • 0
    class Solution:
        def moveZeroes(self, nums):
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            m = 0
            for n in range(len(nums)):
                if nums[n] != 0:
                    nums[m] = nums[n]
                    m += 1
            for i in range(m, n+1):
                nums[i] = 0

Log in to reply

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