반응형
9012 - 괄호 with Python
T = int(input())
for _ in range(T):
cnt = 0
lst = list(input())
if len(lst) == 0:
print('YES')
break
if lst.count('(') != lst.count(')'):
print('NO')
elif lst[0] == ')':
print('NO')
elif lst[-1] == '(':
print('NO')
else:
for i in lst:
if cnt < 0:
print('NO')
break
elif i == '(':
cnt += 1
elif i == ')':
cnt -= 1
if cnt == 0:
print('YES')
'Baekjoon' 카테고리의 다른 글
[Baekjoon] 10815 숫자 카드 (실버 V) - Python (1) | 2023.11.26 |
---|---|
[Baekjoon] 1476 날짜 계산 (실버 V) - Python (0) | 2023.11.24 |
[Baekjoon] 1914번 하노이탑(Silver I) with Python (0) | 2023.05.24 |
[Baekjoon] 9663번 N-Queen(Gold-IV) (0) | 2023.05.23 |
[Baekjoon] 단계별로 풀어보기 2. 조건문 with Python (0) | 2023.04.28 |