aboutsummaryrefslogtreecommitdiff
path: root/challenge-346/eric-cheung/python/ch-1.py
blob: 4ed5e07a061c2ea0a93a5f52b44da3d2f1cefabd (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
## strInput = "(()())"  ## Example 1
## strInput = ")()())"  ## Example 2
## strInput = "((()))()(((()"  ## Example 3
## strInput = "))))((()("  ## Example 4
strInput = "()(()"  ## Example 5

strTemp = strInput
nLastPosFind = len(strInput)
arrPos = []
nCount = 0

while (nPos := strTemp.find("()")) > -1:
    if nPos > nLastPosFind:
        arrPos.append(nCount)
        nCount = 0

    strTemp = strTemp[:nPos] + strTemp[nPos + 2:]
    nLastPosFind = nPos
    nCount = nCount + 2

arrPos.append(nCount)

print (max(arrPos))