Python Solution (Two Pointers)

  • 0

    I put all the border judgment to the exception handling

        def moveZeroes(self, nums):
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            p0, p1= 0, 0  #p0:point Zero,  p1:point Non-Zero
            while True:
                    while nums[p1] == 0: p1 += 1
                    while nums[p0] != 0: p0 += 1
                    if p0 < p1:
                        nums[p0], nums[p1] = nums[p1], nums[p0]
                        p1 = p0

Log in to reply

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