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