https://www.acmicpc.net/problem/9012
문제
내 풀이
import sys
from collections import deque
input = sys.stdin.readline
#뒤에서부터 탐색해서, )는 +1, (는 -1을 통해 검사하는 함수
def countthat(a):
global check
if check < 0:
print("NO")
return
if not a and check == 0:
print("YES")
return
elif check != 0 and not a:
print('NO')
return
if ')' == a[-1]:
a.pop()
check += 1
elif '(' == a[-1]:
a.pop()
check -= 1
countthat(a)
n = int(input())
for _ in range(n):
check = 0
prnthss = deque(list(input().strip()))
countthat(prnthss)
해설
개념자체는 간단하다.
정답 풀이
X
출처:
해석
'sw사관학교 정글 2기 > 02 이분탐색, 분할정복, 스택, 큐, 우선순위 큐' 카테고리의 다른 글
[스택] 백준 10000번 원 영역 with Python3 ★★ (0) | 2021.08.14 |
---|---|
[스택] 백준 2493번 탑 with Python3 (0) | 2021.08.14 |
[이분탐색] 백준 2470번 두 용액 with Python3 ★★ (0) | 2021.08.13 |
[이분탐색] 백준 2110번 공유기 설치 with Python3 ★★ (0) | 2021.08.13 |
[이분탐색] 백준 2805번 나무 자르기 with Python3 ★★ (0) | 2021.08.13 |
댓글