Created
February 9, 2016 16:57
-
-
Save bcambel/f0d2cdc42f301a1c8e43 to your computer and use it in GitHub Desktop.
Move all the zeros in between to the end of the array
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
| def move(arr): | |
| i = 0 | |
| idx = 0 | |
| while i < len(arr) and idx < 12: | |
| if arr[i] == 0: | |
| arr.append(0) | |
| arr.pop(i) | |
| i -= 1 | |
| i += 1 | |
| idx += 1 | |
| return arr | |
| print move([0,1,0,3,12]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment