목록베스트앨범 (1)
컴공생의 다이어리
[프로그래머스] 베스트앨범 - 파이썬(Python)
[프로그래머스] 베스트앨범 - 파이썬(Python) from collections import defaultdict def solution(genres, plays): answer = [] G = defaultdict(int) detail = defaultdict(list) for idx, [g, p] in enumerate(zip(genres, plays)): G[g] += p detail[g].append((p, idx)) for g, _ in sorted(G.items(), key=lambda x: -x[1]): for _, i in sorted(detail[g], key=lambda x: -x[0])[:2]: answer.append(i) return answer 혹은 from collection..
Development/Algorithm & Coding Test
2022. 5. 7. 00:01