백준 9012 - 괄호 (Python3)
코드
n = int(input())
for _ in range(n):
bracket = input()
stack = []
for i in bracket:
if i == '(':
stack.append(i)
elif (i == ')' and stack and stack[-1] == '('):
stack.pop()
else:
stack.append(0)
break
print('NO' if stack else 'YES')
댓글남기기