Created
April 4, 2020 07:36
-
-
Save munguial/8673fcc58c029540ca8d6cef554f5e0d to your computer and use it in GitHub Desktop.
Day 4 - Move zeroes
This file contains 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: | |
def moveZeroes(self, nums: List[int]) -> None: | |
def swap(a: int, b: int, nums: List[int]) -> None: | |
temp = nums[a] | |
nums[a] = nums[b] | |
nums[b] = temp | |
lastNonZeroPos = 0 | |
for i in range(len(nums)): | |
if nums[i] != 0: | |
swap(i, lastNonZeroPos, nums) | |
lastNonZeroPos += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment