Python pop and append


  • 0
    L

    My idea is when the current number in the nums list is 0, pop it out and then append it.
    using index() to make sure it pops the current one.

    class Solution(object):
        def moveZeroes(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            for i in nums:
                if i == 0:
                    nums.append(nums.pop(nums.index(i))) 
    

Log in to reply
 

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