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 |
Tags
- 힙
- 코딩테스트
- 브루트포스
- DP
- MYSQL
- 가상메모리
- level2
- N과M
- dict
- 가상메모리 관리
- level0
- 프로그래머스
- 그리디
- 구현
- 딕셔너리
- python
- BFS
- 스택
- 다익스트라
- BOJ
- 수학
- dfs
- 백준
- programmers
- level1
- 다이나믹 프로그래밍
- 운영체제
- 재귀
- 파이썬
- level3
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [롤케이크 자르기] 파이썬 본문
https://school.programmers.co.kr/learn/courses/30/lessons/132265
from collections import defaultdict
def solution(topping):
answer = 0
a=defaultdict(int) # 형 롤케잌
b=defaultdict(int) # 동생 롤케잌
for t in topping: # 형이 롤케잌 다 가져감
a[t]+=1
for t in topping: #제일 끝부터 하나씩 동생에게 떼어줌
a[t]-=1
if a[t]==0:
a.pop(t)
b[t]+=1
if len(a)==len(b): #만약 토핑 개수가 같다면
answer+=1
return answer
default dict를 이용하여 해결하였다.
먼저 한쪽으로 케이크를 다 몰아준 뒤, 한 토핑씩 반대쪽으로 보내며 체크한다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [미로 탈출] 파이썬 (0) | 2023.04.13 |
---|---|
프로그래머스 level2 [호텔 대실] 파이썬 (0) | 2023.04.12 |
프로그래머스 level1 [과일 장수] 파이썬 (0) | 2023.04.06 |
프로그래머스 level2 [뒤에 있는 큰 수 찾기] 파이썬 (0) | 2023.04.05 |
프로그래머스 level2 [숫자 변환하기] 파이썬 (0) | 2023.04.05 |