미숫가루 마시며 개발중
article thumbnail
99클럽 코테 스터디 10일차 TIL + Kth Largest Element in a Stream
Backend/Python 2024. 7. 31. 16:43

✅ 오늘의 학습 키워드[leetcode] Kth Largest Element in a Stream ✅ Kth Largest Element in a Stream- 문제 - 1차 풀이from typing import Listimport heapqclass KthLargest: def __init__(self, k: int, nums: List[int]): self.k = k self.nums = nums heapq.heapify(self.nums) # 리스트를 최소 힙으로 변환합니다. self.nums = heapq.nlargest(self.k, self.nums) # 가장 큰 k개의 요소만 남기고, 내림차순으로 정렬합니다. def add(self..

article thumbnail
99클럽 코테 스터디 9일차 TIL + Relative Ranks (heapq)
Backend/Python 2024. 7. 30. 12:24

✅ 오늘의 학습 키워드[leetcode] Relative Ranksheapq ✅  Relative Ranks- 문제 - 풀이from typing import Listclass Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: ranking = [(s, index) for index, s in enumerate(score)] sorted_ranking = sorted(ranking, key=lambda x: x[0], reverse=True) result = [""] * len(score) def converted_medal(rank, index): meda..