diff options
Diffstat (limited to 'challenge-249/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-249/eric-cheung/python/ch-2.py | 24 |
1 files changed, 24 insertions, 0 deletions
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))
|
