Created
July 26, 2021 16:27
-
-
Save giacaglia/cbc342afa632c5ebd9bca5a178314d58 to your computer and use it in GitHub Desktop.
Move Zeros to the left of array
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
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