본문 바로가기

Algorithm/BOJ 기초

[백준] 괄호 9012 Python

1
2
3
4
5
6
7
8
9
= int(input())
for i in range(N):
    temp = input()
    while "()" in temp:
        temp = temp.replace("()""")
    if len(temp) > 0:
        print("NO")
    else:
        print("YES")

Stack으로 풀 수 있지만 replace를 이용하여 제거 해나가는 식으로 가능함.