From ef1b6e72f5f8b7b06df4f7f955522b0eb7f554fd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 28 Dec 2022 09:53:11 +0000 Subject: - Added solutions by Niels van Dijke. - Added solutions by Flavio Poletti. - Added solutions by Ali Moradi. - Added solutions by Ulrich Rieke. --- challenge-197/eric-cheung/python/ch-1.py | 10 ++++++++++ challenge-197/eric-cheung/python/ch-2.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 challenge-197/eric-cheung/python/ch-1.py create mode 100755 challenge-197/eric-cheung/python/ch-2.py (limited to 'challenge-197/eric-cheung/python') 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)) -- cgit