You are viewing a single comment's thread. Return to all comments →
Quick solution in Python 3:
def isBalanced(s): history = [] for bracket in s: if bracket == '(': history.append(')') elif bracket == '{': history.append('}') elif bracket == '[': history.append(']') else: if not history or bracket != history.pop(): return 'NO' return 'YES' if not history 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 →
Quick solution in Python 3: