[LeetCode] 1244. Design A Leaderboard
다른 함수들은 모두 간단히 구현이 가능하지만 top을 어떻게 구현하느냐에 따라 효율이 달라진다. list를 heap로 구성하는 heapify를 통해 max heap을 구현후 하나씩 pop하는 방식을 활용해 K개의 가장 높은 점수를 더해 반환했다. import heapq class Leaderboard: def __init__(self): self.dic = defaultdict(int) def addScore(self, playerId: int, score: int) -> None: self.dic[playerId] += score def top(self, K: int) -> int: ret = 0 values = list(self.dic.values()) n_values = [-val for val i..
기술(Tech, IT)/리트코드(LeetCode)
2023. 8. 2. 07:59
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 이코노미스트
- java
- 이코노미스트 에스프레소
- socket programming
- 티스토리챌린지
- tf-idf
- 딕셔너리
- 머신 러닝
- 파이썬
- The Economist Espresso
- 리트코드
- Android
- C++
- vertex shader
- join
- machine learning
- DICTIONARY
- ml
- Hash Map
- leetcode
- Computer Graphics
- I2C
- The Economist
- defaultdict
- 안드로이드
- 소켓 프로그래밍
- min heap
- 투 포인터
- 오블완
- Python
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형