백준 11899번: 괄호 끼워넣기 #Python

ColorlessDia·2024년 7월 28일

algorithm/baekjoon

목록 보기
252/836
from collections import deque

S = input()

stack = deque()

for s in S:
    stack.append(s)

    if s != ')':
        continue
    
    if len(stack) < 2:
        continue
    
    if stack[-2] == '(':
        stack.pop()
        stack.pop()

print(len(stack))

0개의 댓글