You are viewing a single comment's thread. Return to all comments →
Python short solution:
def isBalanced(s): # Complete this function bracket_map = {'}': '{', ')': '(', ']': '['} stack = [] for b in s: if b in bracket_map.values(): # openning stack.append(b) elif b in bracket_map.keys(): # closing if not stack or stack.pop() != bracket_map[b]: return "NO" if not stack: return "YES" else: return "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 →
Python short solution: