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