Skip to content

Instantly share code, notes, and snippets.

@giacaglia
Created July 26, 2021 16:27
Show Gist options
  • Save giacaglia/cbc342afa632c5ebd9bca5a178314d58 to your computer and use it in GitHub Desktop.
Save giacaglia/cbc342afa632c5ebd9bca5a178314d58 to your computer and use it in GitHub Desktop.
Move Zeros to the left of array
def move_zeros_to_left(array):
i = len(array) - 1
j = len(array) - 1
while i >= 0:
if array[i] != 0:
array[j] = array[i]
j -= 1
i -= 1
while j >= 0:
array[j] = 0
j -= 1
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment