본문 바로가기
Beakjoon&프로그래머스/파이썬

[프로그래머스/파이썬] 괄호 회전하기

by 현장 2022. 5. 17.

-Code

def solution(s):
    answer = 0
    for n in range(len(s)):
        stack = []
        if n != 0:
            s = s[1:] + s[0]
        for i in s:
            if stack and stack[-1] == '[' and i == ']':
                stack.pop()
            elif stack and stack[-1] == '{' and i == '}':
                stack.pop()
            elif stack and stack[-1] == '(' and i == ')':
                stack.pop()
            else:
                stack.append(i)
        if not stack:
            answer += 1
    return answer