코딩 테스트 (Coding Test)

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

Universe_lee 2023. 1. 17. 16:02

나의 코드

def check(data):
    tmp = []
    for i in data:
        if i in ['(', '{', '[']:
            tmp.append(i)

        else:
            if tmp:
                if i == ')' and tmp[-1] == '(':
                    tmp.pop()

                elif i == '}' and tmp[-1] == '{':
                    tmp.pop()

                elif i == ']' and tmp[-1] == '[':
                    tmp.pop()
            else:
                return False

    return False if any(tmp) else True

def solution(s):
    answer = 0
    for i in range(len(s)):
        if check(s[i + 1:] + s[:i + 1]):
            answer += 1
    return answer