I can't understand why i coundn't append zero to nums


  • 0
    L
    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)
        cnt_zero = 0
        for num in nums:
            if not num:
                cnt_zero += 1
        nums[:] =[n for n in nums if n]
        nums = nums + [0] * cnt_zero

  • 0

    perhaps this is not in-place?


Log in to reply
 

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