Python O(n) solution


  • 0

    If you don't like sort.

    class Solution(object):
        def moveZeroes(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            not_filtered_len = len(nums)
            nums[:] = filter(lambda x: x != 0, nums)
            nums += [0] * (not_filtered_len - len(nums))
    

    :levitate:


Log in to reply
 

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