Python Solution ( Asking for better solution )


  • 1
    R
    class Solution(object):
        def moveZeroes(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            i = 0
            
            # Add a sentinel to the end of the list
            nums.append('A')
            while nums[i] != 'A':
                if nums[i] == 0:
                    nums.pop(i)
                    nums.append(0)
                else:
                    i += 1
            nums.pop(i)
     
    

Log in to reply
 

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