n = int(input())
for _ in range(n):
m = input()
l = []
for i in m:
if i == "(":
l.append("(")
else:
if len(l) != 0 and l[-1] == "(":
l.pop()
else:
l.append(")")
if len(l) == 0:
print("YES")
else:
print("NO")
저번에 푼 4949번과 똑같은 알고리즘이다
(일때는 append
)일때는 조건을 만족하면 pop하고 아니면 append한다
'알고리즘' 카테고리의 다른 글
<백준> 10773번 파이썬 알고리즘 (0) | 2021.07.10 |
---|---|
<백준> 10250번 파이썬 알고리즘 (0) | 2021.07.10 |
<백준> 7568번 파이썬 알고리즘 (0) | 2021.07.10 |
<백준> 4949번 파이썬 알고리즘 (0) | 2021.07.10 |
<백준> 2869번 파이썬 알고리즘 (0) | 2021.07.09 |