leetcode75 43

Heap-PrioiryQueue: 215. Kth Largest Element in an Array ★

215. Kth Largest Element in an Array class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: # minheap 으로 만들고, k개 까지. 힙 개수 유지하게 하면, # k 개 보다 많으면 작은 것들 제거 # 그렇게 하면, minheap[0]에는 k번째 큰 것이 남아있음 heapq.heapify(nums) while( len(nums) > k): heapq.heappop(nums) return nums[0] 메모리 절약을 위해, k 개 만큼 우선 넣어서, minheap 만들고.1개씩 추가해서, k개 넘는..

BST: 875. Koko Eating Bananas ★

875. Koko Eating Bananas https://youtu.be/U2SozAs9RzA?si=lxNzqfZ1jL_lzHUX from math import ceilfrom typing import Listclass Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: # 이진 탐색 범위 설정 # 최소 속도는 1 (최소 한 개라도 먹음), 최대 속도는 max(piles) (한 번에 가장 큰 더미를 모두 먹음) # Set the binary search range: # Minimum speed is 1 (at least one banana per hour), and maximu..

LeetCode/LeetCode75 2024.11.22

[LeetCode 75] Medium - 2300. Successful Pairs of Spells and Potions

2300. Successful Pairs of Spells and Potions https://youtu.be/OKnm5oyAhWg?si=k_d-0f6Nt10xOCD6 class Solution: def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: # spell * potion >= success 를 만족하는 쌍을 찾아야 함 # 이를 변형하면: potion >= success / spell 이 됨 # 즉, potion의 값이 특정 기준값 이상인 경우를 찾아야 함. # 1. potions 리스트를 정렬하여 이진 탐색을 수행 가능하도록 준비..

LeetCode/LeetCode75 2024.11.22