You are viewing a single comment's thread. Return to all comments →
def isBalanced(s): _map={')': '(', ']':'[', '}':'{'} q=[] for character in s: if character in '([{': q.append(character) elif character in ')]}': if not q: return 'NO' last=q.pop() if last!=_map[character]: return 'NO' return 'YES' if not q else 'NO'
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 →