You are viewing a single comment's thread. Return to all comments →
Adding my python3 solution here for convenience:
def check_str(string): stack = [] table = { ")": "(", "}": "{", "]": "[", } for char in string: if not stack: stack.append(char) elif char not in table: stack.append(char) elif table[char] == stack[-1]: stack.pop() else: stack.append(char) if stack: print("NO") else: print("YES") N = int(input().strip()) for i in range(N): check_str(input())
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 →
Adding my python3 solution here for convenience: