롤케이크 자르기
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 내 풀이
- Counter 사용하고
- 시간초과나서 최대한 연산 횟수 줄이도록 코드 수정
- 매번 count로 계산하지 않고 dict_cnt[t]<=0이 되는지 체크하며 진행
from collections import Counter
def solution(topping):
answer = 0
dict_cnt=Counter(topping)
n=len(set(topping))
m=0
set1=set()
for t in topping:
if t not in set1:
m+=1
set1.add(t)
dict_cnt[t]-=1
if dict_cnt[t]<=0:
n-=1
if n==m:
answer+=1
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스][완전탐색] 16498. 작은 벌점 (0) | 2024.11.21 |
|---|---|
| [프로그래머스][BFS/DFS] 빛의 경로 사이클 (0) | 2024.11.20 |
| [프로그래머스] [DP] 숫자 변환하기 (1) | 2024.11.16 |
| [프로그래머스][구현] 오픈채팅방 (0) | 2024.11.01 |
| [프로그래머스][DP] 등굣길 (0) | 2024.11.01 |