Skip to content

Instantly share code, notes, and snippets.

@nukeguys
Created July 23, 2018 11:23
def solution(S):
stack = []
parenDic = {'(':0, ')':0, '{':1, '}':1, '[':2, ']':2}
for c in S:
if c in ['(', '[', '{']:
stack.append(c)
else:
if len(stack) == 0:
return 0
p = stack.pop()
if parenDic[c] != parenDic[p]:
return 0
if len(stack) != 0:
return 0
else:
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment