討論串[閒聊] 每日leetcode
共 1554 篇文章
內容預覽:
2762. Continuous Subarrays. ## 思路. sliding window. 用counter記錄window裡面的值跟個數. ## Code. ```python. class Solution:. def continuousSubarrays(self, nums: L
(還有365個字)
內容預覽:
2593. Find Score of an Array After Marking All Elements. ## 思路. 建(num, idx) 的min heap. 每次pop檢查idx有沒有mark過, 沒有就+score並mark. ## Code. ```python. class S
(還有388個字)
內容預覽:
def pickGifts(self, gifts: List[int], k: int) -> int:. pq = [-g for g in gifts]. heapify(pq). for i in range(k):. cur_num = -heappop(pq). heappush(pq,
(還有52個字)
內容預覽:
2558. Take Gifts From the Richest Pile. ## 思路. max heap. ## Code. ```python. class Solution:. def pickGifts(self, gifts: List[int], k: int) -> int:. m
(還有597個字)