diff options
Diffstat (limited to 'challenge-333/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-333/eric-cheung/python/ch-2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-333/eric-cheung/python/ch-2.py b/challenge-333/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..7e96b1df40 --- /dev/null +++ b/challenge-333/eric-cheung/python/ch-2.py @@ -0,0 +1,17 @@ +
+## arrInt = [1, 0, 2, 3, 0, 4, 5, 0] ## Example 1
+## arrInt = [1, 2, 3] ## Example 2
+## arrInt = [1, 2, 3, 0] ## Example 3
+## arrInt = [0, 0, 1, 2] ## Example 4
+arrInt = [1, 2, 0, 3, 4] ## Example 5
+
+arrOut = arrInt[:]
+
+arrZeroPos = [nPos for nPos, nElem in enumerate(arrInt) if nElem == 0]
+
+if len(arrZeroPos) == 0:
+ print (arrOut)
+else:
+ for nPos in arrZeroPos[::-1]:
+ arrOut.insert(nPos, 0)
+ print (arrOut[:len(arrInt)])
|
