You are viewing a single comment's thread. Return to all comments →
Elegant python3 solution
def isBalanced(s): stack = deque() pairs = { ")":"(", "}":"{", "]":"[" } for i in s: if i not in pairs: stack.append(i) elif not stack or stack.pop() != pairs[i]: return "NO" return "NO" if stack 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 →
Elegant python3 solution