diff options
Diffstat (limited to 'challenge-215/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-215/eric-cheung/python/ch-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-215/eric-cheung/python/ch-2.py b/challenge-215/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..8c366a73f6 --- /dev/null +++ b/challenge-215/eric-cheung/python/ch-2.py @@ -0,0 +1,26 @@ +
+## Example 1
+## arrNum = [1, 0, 0, 0, 1]
+## nCount = 1
+
+## Example 2
+## arrNum = [1, 0, 0, 0, 1]
+## nCount = 2
+
+## Example 3
+arrNum = [1, 0, 0, 0, 0, 0, 0, 0, 1]
+nCount = 3
+
+for nIndxLoop in range(1, len(arrNum) - 1):
+
+ if nCount == 0:
+ break
+
+ if arrNum[nIndxLoop - 1] == 0 and arrNum[nIndxLoop] == 0 and arrNum[nIndxLoop + 1] == 0:
+ arrNum[nIndxLoop] = 1
+ nCount = nCount - 1
+
+if nCount == 0:
+ print (1)
+else:
+ print (0)
|
