백준 3986번: 좋은 단어 #Python

ColorlessDia·2024년 7월 27일

algorithm/baekjoon

목록 보기
251/808
import sys
from collections import deque

N = int(sys.stdin.readline())

count = 0

for _ in range(N):
    word = sys.stdin.readline().rstrip()

    stack = deque()

    for char in word:
        stack.append(char)

        if len(stack) < 2:
            continue
        
        if stack[-1] == stack[-2]:
            stack.pop()
            stack.pop()

    if len(stack) == 0:
        count += 1

print(count)

0개의 댓글