Simple Python solution (Beats 83%)


  • 0
    X
    class Solution(object):
        def moveZeroes(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            l = len(nums)
            k = 0
            for num in nums:
                if num!=0:
                    nums[k] = num
                    k += 1
                else:
                    continue
            nums[k:l]=[0]*(l-k)
    

  • 0
    X

    Last line is not elegant. You're creating a new list. Why not use xrange?


Log in to reply
 

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