LeetCode 329

[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

[LeetCode 75] Medium - 2462. Total Cost to Hire K Workers

2462. Total Cost to Hire K Workers class Solution: def totalCost(self, costs: List[int], k: int, candidates: int) -> int: n = len(costs) # 근로자의 총 수 # **교차점 처리**: # 만약 앞부분(pre)과 뒷부분(suf)이 겹치는 경우: # 전체를 정렬한 뒤, k명의 최소 비용을 더한 값을 반환. if 2 * candidates + k > n: costs.sort() # 비용 정렬 return sum(costs[:k]) # k개의 최소값을 반환 # **초기화..

LeetCode/LeetCode75 2024.11.19