mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-15 09:57:09 +00:00
Time: 35 ms (96.78%), Space: 28.7 MB (69.5%) - LeetHub
This commit is contained in:
@@ -10,7 +10,8 @@ class Solution:
|
|||||||
# iterate over k+1...n - O(n) times
|
# iterate over k+1...n - O(n) times
|
||||||
# - if larger than min in heap, replace min - O(log k)
|
# - if larger than min in heap, replace min - O(log k)
|
||||||
# - else do nothing
|
# - else do nothing
|
||||||
for num in nums:
|
for i in range(k, len(nums)):
|
||||||
|
num = nums[i]
|
||||||
if num > heap[0]:
|
if num > heap[0]:
|
||||||
heapq.heapreplace(heap, num)
|
heapq.heapreplace(heap, num)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user