[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
- tf-idf
- 딕셔너리
- 파이썬
- Hash Map
- C++
- 이코노미스트
- 머신 러닝
- leetcode
- 투 포인터
- defaultdict
- Python
- vertex shader
- Computer Graphics
- 소켓 프로그래밍
- 리트코드
- java
- ml
- DICTIONARY
- The Economist
- 이코노미스트 에스프레소
- join
- socket programming
- The Economist Espresso
- min heap
- Android
- machine learning
- 티스토리챌린지
- I2C
- 안드로이드
- 오블완
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형