★DEQUE★split()★괄호 회전하기[프로그래머스]
2023. 4. 26. 21:46
728x90
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/76502
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
VERSION 2.0
from collections import deque
def solution(s):
answer = 0
B = deque([i for i in s])
for tt in range(len(s)):
A = deque()
for i in B:
if len(A) == 0:
A.append(i)
else:
if i == ")" and A[-1] == "(":
A.pop()
elif i == "]" and A[-1] == "[":
A.pop()
elif i == "}" and A[-1] == "{":
A.pop()
else:
A.append(i)
B.append(B.popleft())
if len(A)==0:
answer +=1
return answer
VERSION 1.0
from collections import deque
def solution(s):
answer = -1
rot = len(s) # s를 x칸만큼 회전
s = deque(s)
a = deque(s)
cnt =0
for i in range(rot):
a = deque(s)
while True:
a = "".join(map(str , a))
if '()' in a:
a = a.split('()')
elif '[]' in a:
a = a.split('[]')
elif '{}' in a:
a = a.split('{}')
else:
break
s.append(s.popleft())
if len(a) == 0:
print(a)
cnt +=1
return cnt728x90
반응형
'Python(프로그래머스) > 스택,큐' 카테고리의 다른 글
| ★스택★뒤에 있는 큰 수 찾기[프로그래머스] (0) | 2023.06.19 |
|---|---|
| ★리스트★스택★같은 숫자는 싫어[프로그래머스] (1) | 2023.06.18 |
| ★VER3.0★Deque★문자열슬라이싱★같은 숫자는 싫어[프로그래머스] (1) | 2023.01.03 |
| ★DEQUE★다리를 지나는 트럭[프로그래머스] (0) | 2022.11.29 |
| ★DEQUE★enumerate★프린터[프로그래머스] (0) | 2022.11.19 |