Python solution


  • 0
    Y

    class Solution(object):
    def moveZeroes(self, nums):
    len1 = len(nums)
    if len1 <= 1:
    return
    start0 = 0
    start1 = 0
    while start0 < len1 and start1 < len1:
    while start0 < len1 and nums[start0] != 0:
    start0 += 1
    while start1 < len1 and nums[start1] == 0:
    start1 += 1
    if start0 < start1 and start0 < len1 and start1 < len1:
    nums[start0], nums[start1] = nums[start1], nums[start0]
    start0 += 1
    start1 += 1


Log in to reply
 

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