반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 운영체제
- 프로그래머스
- 수학
- 에라스토테네스의 체
- 브루트포스
- level0
- programmers
- 백준
- 가상메모리
- python
- BFS
- 힙
- 코딩테스트
- 다익스트라
- DP
- level2
- 그리디
- 구현
- level1
- N과M
- 딕셔너리
- 다이나믹 프로그래밍
- BOJ
- 가상메모리 관리
- dfs
- 파이썬
- 재귀
- level3
- 스택
- MYSQL
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [괄호 회전하기] 파이썬 본문
반응형
https://programmers.co.kr/learn/courses/30/lessons/76502
코딩테스트 연습 - 괄호 회전하기
programmers.co.kr
#프로그래머스 괄호 회전하기 다른사람풀이
def solution(s):
answer = 0
temp = list(s)
for _ in range(len(s)):
st = []
for i in range(len(temp)):
if len(st) > 0:
if st[-1] == '[' and temp[i] == ']':
st.pop()
elif st[-1] == '(' and temp[i] == ')':
st.pop()
elif st[-1] == '{' and temp[i] == '}':
st.pop()
else:
st.append(temp[i])
else:
st.append(temp[i])
if len(st) == 0:
answer += 1
temp.append(temp.pop(0))
return answer
하나하나씩 다 회전하는걸 시도하지 못했다... 위의 풀이를 참고해서 다시 풀이를 수정하였다.
#프로그래머스 괄호 회전하기
def solution(s):
answer = 0
s=list(map(str,s))
if len(s)%2==1:
return 0
else:
for _ in range(len(s)):
lst=[]
for i in range(len(s)):
lst.append(s[i])
if len(lst)>1:
if lst[-2]=='(' and lst[-1]==')':
lst.pop()
lst.pop()
elif lst[-2]=='{' and lst[-1]=='}':
lst.pop()
lst.pop()
elif lst[-2]=='[' and lst[-1]==']':
lst.pop()
lst.pop()
if not lst:
answer+=1
s.append(s.pop(0))
return answer
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [모음사전] 파이썬 (0) | 2021.12.07 |
---|---|
프로그래머스 level2 [주식가격] 파이썬 (0) | 2021.12.07 |
프로그래머스 level2 [짝지어 제거하기] 파이썬 (0) | 2021.12.06 |
프로그래머스 level2 [이진 변환 반복하기] 파이썬 (0) | 2021.12.06 |
프로그래머스 level2 [점프와 순간 이동] 파이썬 (0) | 2021.12.06 |