Skip to content

Commit

Permalink
Merge pull request anmolrishi#35 from Kansattica/master
Browse files Browse the repository at this point in the history
Add python implementation of zeros_to_tail
anmolrishi authored Oct 27, 2018

Unverified

This user has not yet uploaded their public signing key.
2 parents 5a51deb + b9e0bdc commit d47883e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Arrays/zeros_to_tail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

def zeros_to_tail(arr):
zeroes = 0
end_of_nonzero_numbers = 0
for num in arr:
if num == 0:
zeroes += 1
else:
arr[end_of_nonzero_numbers] = num
end_of_nonzero_numbers += 1
for idx in range(end_of_nonzero_numbers, len(arr)):
arr[idx] = 0
return arr



test = [1, 0, 2, 0, 3, 0, 0, 0, 4, 5, 0, 69, 0]

print(zeros_to_tail(test))

0 comments on commit d47883e

Please sign in to comment.