diff options
Diffstat (limited to 'challenge-197/eric-cheung/python')
| -rwxr-xr-x | challenge-197/eric-cheung/python/ch-1.py | 10 | ||||
| -rwxr-xr-x | challenge-197/eric-cheung/python/ch-2.py | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-197/eric-cheung/python/ch-1.py b/challenge-197/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..b84bff5774 --- /dev/null +++ b/challenge-197/eric-cheung/python/ch-1.py @@ -0,0 +1,10 @@ +
+import numpy as np
+
+## arrInputList = np.array([1, 0, 3, 0, 0, 5]) ## Example 1
+## arrInputList = np.array([1, 6, 4]) ## Example 2
+arrInputList = np.array([0, 1, 0, 2, 0]) ## Example 3
+
+arrOutputList = np.append(arrInputList[arrInputList != 0], arrInputList[arrInputList == 0])
+
+print (arrOutputList)
diff --git a/challenge-197/eric-cheung/python/ch-2.py b/challenge-197/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..f95f735238 --- /dev/null +++ b/challenge-197/eric-cheung/python/ch-2.py @@ -0,0 +1,23 @@ +
+## Remarks
+## https://zhenyu0519.github.io/2020/07/12/lc280/
+
+def wiggleSort(arrSubInput):
+
+ bGtr = False
+ arrSubOutput = arrSubInput
+
+ for nLoop in range(len(arrSubOutput) - 1):
+ if bGtr and arrSubOutput[nLoop] <= arrSubOutput[nLoop + 1] or not bGtr and arrSubOutput[nLoop] >= arrSubOutput[nLoop + 1]:
+ arrSubOutput[nLoop], arrSubOutput[nLoop + 1] = arrSubOutput[nLoop + 1], arrSubOutput[nLoop]
+
+ bGtr = not bGtr
+
+ return arrSubOutput
+
+
+## arrInputList = [1, 5, 1, 1, 6, 4] ## Example 1
+## arrInputList = [1, 3, 2, 2, 3, 1] ## Example 2
+arrInputList = [1, 5, 2, 3, 4, 6] ## Example
+
+print (wiggleSort(arrInputList))
|
