aboutsummaryrefslogtreecommitdiff
path: root/challenge-197/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-197/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-197/eric-cheung/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
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))