You are viewing a single comment's thread. Return to all comments →
Python 3:
def isBalanced(s): # Write your code here opening = [] for bracket in s: if bracket in ["(", "{", "["]: opening.append(bracket) else: try: pair = opening.pop() if pair=="(" and bracket!=")": return 'NO' if pair=="{" and bracket!="}": return 'NO' if pair=="[" and bracket!="]": return 'NO' except Exception: return 'NO' if opening: return 'NO' else: return '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 →
Python 3: