Skip to content

Instantly share code, notes, and snippets.

@munguial
Created April 4, 2020 07:36
Show Gist options
  • Save munguial/8673fcc58c029540ca8d6cef554f5e0d to your computer and use it in GitHub Desktop.
Save munguial/8673fcc58c029540ca8d6cef554f5e0d to your computer and use it in GitHub Desktop.
Day 4 - Move zeroes
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