From e056520665a1179416e001742a7c11a504548c51 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 26 Dec 2023 20:19:29 +0000 Subject: - Added solutions by Eric Cheung. --- challenge-249/eric-cheung/python/ch-1.py | 16 ++++++++++++++++ challenge-249/eric-cheung/python/ch-2.py | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 challenge-249/eric-cheung/python/ch-1.py create mode 100755 challenge-249/eric-cheung/python/ch-2.py (limited to 'challenge-249/eric-cheung/python') diff --git a/challenge-249/eric-cheung/python/ch-1.py b/challenge-249/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..e41155cc52 --- /dev/null +++ b/challenge-249/eric-cheung/python/ch-1.py @@ -0,0 +1,16 @@ + +arrInt = [3, 2, 3, 2, 2, 2] ## Example 1 +## arrInt = [1, 2, 3, 4] ## Example 2 + +arrUniq = list(set(arrInt)) +arrCount = [arrInt.count(nLoop) for nLoop in arrUniq] +arrOutput = [] + +if any(nLoop % 2 == 1 for nLoop in arrCount): + print ([]) +else: + for nIndx in range(len(arrUniq)): + for nCount in range(int(arrCount[nIndx] / 2)): + arrOutput.append([arrUniq[nIndx], arrUniq[nIndx]]) + + print (arrOutput) diff --git a/challenge-249/eric-cheung/python/ch-2.py b/challenge-249/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..79efde5aea --- /dev/null +++ b/challenge-249/eric-cheung/python/ch-2.py @@ -0,0 +1,24 @@ + +## Ref. +## https://leetcode.com/problems/di-string-match/ +## https://algo.monster/liteproblems/942 + +def GetDiStrMatch (strInput): + + arrOutput = [] + nLow, nHigh = 0, len(strInput) + for charLoop in strInput: + if charLoop == "I": + arrOutput.append(nLow) + nLow = nLow + 1 + else: + arrOutput.append(nHigh) + nHigh = nHigh - 1 + arrOutput.append(nLow) + return arrOutput + +## strExample = "IDID" ## Example 1 +## strExample = "III" ## Example 2 +strExample = "DDI" ## Example 3 + +print (GetDiStrMatch(strExample)) -- cgit