Created
April 5, 2020 02:12
-
-
Save yesidays/dcd72ed5e2c9f644971b5816da4879ad to your computer and use it in GitHub Desktop.
Move zeroes - Leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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