programmers | Lv2. 괄호 회전하기 [Python]

yeonk·2022년 3월 15일
0

algorithm

목록 보기
74/88
post-thumbnail

💡 Python 3






🔗 문제

괄호 회전하기 [Link]






💻 코드

def solution(s):
    l1, l2 = ['(', '{', '['], [')', '}', ']']
    def check(c, ns):
        for n in ns:
            if n in l1: c.append(n)
            elif c == []: return 0
            elif c.pop() != l1[l2.index(n)]: return 0
        return 0 if c else 1
    
    count = 0
    for i in range(len(s)):
        c, ns = [], s[i:] + s[:i]
        count += check(c, ns)
    return count

0개의 댓글