You are viewing a single comment's thread. Return to all comments →
python implementation
def isBalanced(s): check = {")":"(" , "]":"[" , "}":"{" } stack = [] for c in s: if c in check.values(): stack.append(c) elif stack and check[c] == stack[-1]: stack.pop() else: return 'NO' if stack == []: return 'YES' else: return 'NO'
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
python implementation