-Code
def solution(s):
answer = 0
for n in range(len(s)):
stack = []
if n != 0:
s = s[1:] + s[0]
for i in s:
if stack and stack[-1] == '[' and i == ']':
stack.pop()
elif stack and stack[-1] == '{' and i == '}':
stack.pop()
elif stack and stack[-1] == '(' and i == ')':
stack.pop()
else:
stack.append(i)
if not stack:
answer += 1
return answer
'Beakjoon&프로그래머스 > 파이썬' 카테고리의 다른 글
[프로그래머스/파이썬] 피보나치 수 (0) | 2022.05.17 |
---|---|
[프로그래머스/파이썬] 올바른 괄호 (0) | 2022.05.17 |
[프로그래머스/파이썬] 튜플 (0) | 2022.05.17 |
[프로그래머스/파이썬] 짝지어 제거하기 (0) | 2022.05.17 |
[프로그래머스/파이썬] 가장 큰 수 (0) | 2022.05.17 |