O(n) Python with 91%beat

  • 2

    class Solution(object):

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


Log in to reply

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