Link : https://programmers.co.kr/learn/courses/30/lessons/76502
Python
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
from collections import deque
def solution(s):
deq = deque(s[:])
result = 0
length = len(s)
for i in range(length):
temp = deq.popleft()
deq.append(temp)
stack = []
for i in deq:
if len(stack) == 0:
if i in [')', ']', '}']:
break
stack.append(i)
else:
if i in ['(', '[', '{', ')', ']', '}']:
if stack[-1] == '(' and i == ')':
stack.pop()
elif stack[-1] == '[' and i == ']':
stack.pop()
elif stack[-1] == '{' and i == '}':
stack.pop()
else:
stack.append(i)
else:
if len(stack) == 0:
result += 1
return result
|
cs |
FeedBack
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
PROGRAMMERS 42842: 카펫 (0) | 2021.07.18 |
---|---|
PROGRAMMERS 77485: 행렬 테두리 회전하기 (0) | 2021.06.21 |
PROGRAMMERS 12985: 예상 대진표 (0) | 2021.04.05 |
PROGRAMMERS 17684: [3차] 압축 (0) | 2021.04.05 |
PROGRAMMERS 1844: 게임 맵 최단거리 (0) | 2021.04.02 |
댓글