레벨2 문제
from collections import deque
def solution(s):
answer = 0
for i in range(len(s)):
temp = s[i:] + s[:i]
answer += check(temp)
return answer
def check(k):
k = deque(k)
arr = []
while k:
n = k.popleft()
if ( n in ('[', '(', '{') ):
arr.append(n)
else:
if ( n == ']' and len(arr) != 0 and arr[-1] == '[' ):
arr.pop()
elif ( n == ')' and len(arr) != 0 and arr[-1] == '(' ):
arr.pop()
elif ( n == '}' and len(arr) != 0 and arr[-1] == '{' ):
arr.pop()
else:
arr.append(n)
if len(arr) == 0:
num = 1
else:
num = 0
return num