Simple standard two pointer method for Python


  • 0
    K
    class Solution(object):
        def moveZeroes(self, nums):
            j = 0
            for i, num in enumerate(nums):
                nums[j] = nums[i]
                if nums[j] != 0:
                    j += 1
            for i in range(j, len(nums)):
                nums[i] = 0
    

Log in to reply
 

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