You are viewing a single comment's thread. Return to all comments →
def isBalanced(s): closeToOpen = { ")" : "(", "]" : "[", "}" : "{" } Stack = [] for x in s: if x in closeToOpen: if Stack and Stack[-1] == closeToOpen[x]: Stack.pop() else: return "NO" else: Stack.append(x) return "NO" if len(Stack) > 0 else "YES"
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →