728x90
반응형
기본적인 스택 문제이다. 딱 작년만 해도 이 문제를 못 풀었었는데 이제는 쉽게 풀 수 있게 되었다. 굿!!
from collections import deque
s = input()
stack = deque()
res = 0
for c in s:
if c == '(':
stack.append(c)
else:
if stack[-1] == '(':
stack.pop()
stack.append(1)
else:
t = 0
while stack[-1] != '(':
t += stack.pop()
stack.pop()
stack.append(t)
res += t+1
print(res)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1918번 후위 표기식(python) (0) | 2021.03.07 |
---|---|
백준 알고리즘 2493번 탑(python) (0) | 2021.03.07 |
백준 알고리즘 13015번 별 찍기 - 23(python) (0) | 2021.03.07 |
백준 알고리즘 10995번 별 찍기 - 20(python) (0) | 2021.03.07 |
백준 알고리즘 2556번 별 찍기 - 14(python) (0) | 2021.03.07 |