
1번 풀이
for _ in range(int(input())):
stack = []
p = input()
for i in p:
if i == "(":
stack.append(i)
else:
if not stack:
stack.append(i)
break
else:
stack.pop()
if not stack:
print("YES")
else:
print("NO")
2번 풀이
import sys
input = sys.stdin.readline
for _ in range(int(input())):
stack = 0
p = input()
for i in p:
if stack < 0:
print("NO")
break
if i == "(":
stack += 1
elif i == ")":
stack -= 1
if stack == 0:
print("YES")
elif stack > 0:
print("NO")
| [파이썬/python] 백준 1874번 : 스택 수열(🥈2) (0) | 2023.05.30 |
|---|---|
| [파이썬/python] 백준 4949번 : 균형잡힌 세상(🥈3) (0) | 2023.05.26 |
| [파이썬/python] 백준 10828번 : 스택(🥈4) (0) | 2023.05.26 |
| [파이썬/python] 백준 20920번 : 영단어 암기는 괴로워(🥈3) (0) | 2023.05.26 |
| [파이썬/python] 백준 26069번 : 붙임성 좋은 총총이(🥈4) (0) | 2023.05.25 |