diff options
Diffstat (limited to 'challenge-235/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-235/packy-anderson/python/ch-2.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-235/packy-anderson/python/ch-2.py b/challenge-235/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..fe63f8bea3 --- /dev/null +++ b/challenge-235/packy-anderson/python/ch-2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +def duplicateZeros(ints): + length = len(ints) + skip_me = -1 + for i in range(0, length): + if skip_me == i: + continue + if ints[i] == 0: + ints.insert(i+1, 0) # insert a 0 at i+1 + ints.pop(-1) # pop the last element off ints + skip_me = i+1 # skip over the 0 we added! + return ints + +def solution(ints): + intlist = ", ".join([ str(i) for i in ints ]) + print(f'Input: @ints = ({ intlist })') + ints = duplicateZeros(ints) + intlist = ", ".join([ str(i) for i in ints ]) + print(f'Output: ({ intlist })'); + +print("Example 1:") +solution([1, 0, 2, 3, 0, 4, 5, 0]) + +print("\nExample 2:") +solution([1, 2, 3]) + +print("\nExample 3:") +solution([0, 3, 0, 4, 5])
\ No newline at end of file |
