ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

괄호 회전하기 #269

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image

ji-0630 commented 1 year ago

나의 풀이

def solution(s):
    answer = len(s)

    if answer % 2 == 1:
        return 0

    for i in range(len(s)):
        lst = s[i:] + s[:i]

        if lst[0] == "}" or lst[0] == "]" or lst[0] == ")": 
            answer -= 1
        else:
            tmp = []
            for j in lst:              
                if j == "{" or j == "[" or j == "(":
                    tmp.append(j)
                elif j == "}":
                    if len(tmp) != 0 and tmp[-1] == "{":
                        tmp.pop()
                    else:
                        answer -= 1 
                        break
                elif j == "]":
                    if len(tmp) != 0 and tmp[-1] == "[":
                        tmp.pop()
                    else:
                        answer -= 1
                        break
                elif j == ")":
                    if len(tmp) != 0 and tmp[-1] == "(":
                        tmp.pop()
                    else:
                        answer -= 1
                        break
            tmp =[]     

    return answer