programmers- lv.2 (괄호 회전하기)

이예송·2023년 8월 2일

PS

목록 보기
72/97

문제링크: 괄호 회전하기

✍🏻 Information

content
언어python
난이도⭐️⭐️
풀이시간10분
제출횟수1
인터넷검색유무no




🍒 My Code

def isright(s):
    stack = []
    opens,closes = ['[','(','{'],[']',')','}']
    for i in s:
        if i in opens:
            stack.append(i)
        else:
            if len(stack)==0:
                return False
            if stack[-1] in opens and opens.index(stack[-1])==closes.index(i):
                stack.pop()
    return len(stack)==0

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




💡 What I learned

  • s[i:len(s)]는 s[i:]로도 쓸 수 있다.

0개의 댓글