The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
looked = []
inpt = '})[]((([(]))(){'
#inpt = "})[]((([(]))(){";
#inpt = "(}){}";
#inpt = "{{{{{{{";
count = 0;
def findMatch(e, looked):
if len(looked):
op = looked.pop(len(looked)-1)
if ((e == '}' and op == '{') or (e == ')' and op == '(') or (e == ']' and op == '[')):
return 1
innerCount = findMatch(e, looked)
if innerCount > 0:
return innerCount
else:
looked.append(e)
return 0
return 0
for i in range(0, len(inpt)):
e = inpt[i]
if e =='{' or e =='(' or e =='[':
looked.append(e)
else:
count = count + findMatch(e, looked)
print(count)