최대 1 분 소요

Python

import collections
def solution(s):
    answer = 0
    q: deque = collections.deque(s)
    table = {
            ')' : '(',
            '}' : '{',
            ']' : '[',
        }
    
    for i in s:
        boolean = True
        temp = []        
        for j in q:
            if j not in table:
                temp.append(j)
            elif not temp or table[j] != temp.pop():
                boolean = False
                break
        if boolean == True and not temp:
            answer += 1        
        q.append(q.popleft())
        
    return answer

댓글남기기