Skip to content

Instantly share code, notes, and snippets.

@bcambel
Created February 9, 2016 16:57
Show Gist options
  • Select an option

  • Save bcambel/f0d2cdc42f301a1c8e43 to your computer and use it in GitHub Desktop.

Select an option

Save bcambel/f0d2cdc42f301a1c8e43 to your computer and use it in GitHub Desktop.
Move all the zeros in between to the end of the array
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