[프로그래머스] 괄호 회전하기

단간단간·2024년 4월 18일
0

알고리즘 문제

목록 보기
71/106

문제 링크:

https://school.programmers.co.kr/learn/courses/30/lessons/76502

python

def check(s):
    stack = []
    for c in s:
        if stack and (
                (c == "]" and stack[-1] == "[") or (c == ")" and stack[-1] == "(") or (c == "}" and stack[-1] == "{")):
            stack.pop()
        else:
            stack.append(c)

    return False if stack else True


def solution(s):
    count = 0
    for i in range(len(s)):
        count += check(s[i:] + s[:i])

    return count


if __name__ == "__main__":
    result = solution("[](){}")
    print(result)
3
profile
simple is best

0개의 댓글