Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input = [0,1,2,2,2,0,1, 0,2,1,0,0,2,2]
- #input = [1,0,1]
- N = len(input)
- print input
- z=0
- t=N-1
- c=0
- i=0
- while i != t+1:
- c+=1
- if input[i] == 0:
- if input[z]==0:
- i+=1
- else:
- input[i]=input[z]
- input[z]=0
- i+=1
- z+=1
- elif input[i] == 2:
- if input[t] == 2:
- pass
- else:
- input[i]=input[t]
- input[t]=2
- t-=1
- else:
- i+=1
- print input
- print N, c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement