Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created April 5, 2020 02:12
Show Gist options
  • Save yesidays/dcd72ed5e2c9f644971b5816da4879ad to your computer and use it in GitHub Desktop.
Save yesidays/dcd72ed5e2c9f644971b5816da4879ad to your computer and use it in GitHub Desktop.
Move zeroes - Leetcode
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
count = 0
for i, num in enumerate(nums):
if num == 0:
count += 1
else:
pos = i - count
nums[pos] = num
if i >= count and count > 0:
nums[i] = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment