aboutsummaryrefslogtreecommitdiff
path: root/challenge-249/eric-cheung/python/ch-2.py
blob: 79efde5aea331fa55eafb2b7a78ee4a794ef85a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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))