You are viewing a single comment's thread. Return to all comments →
A slightly shorter version ;)
table = { ')': '(', ']':'[', '}':'{' } for _ in range(int(input())): stack = [] for x in input(): if stack and table.get(x) == stack[-1]: stack.pop() else: stack.append(x) print("NO" if stack else "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 →
A slightly shorter version ;)