We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab9ff35 commit 8cbcf1dCopy full SHA for 8cbcf1d
Python/sliding-window-median.py
@@ -68,7 +68,7 @@ def rebuild_heap(heap, to_remove, sign): # Time: O(k), Space: O(k)
68
if not to_remove[min_heap[0]]:
69
del to_remove[min_heap[0]]
70
heapq.heappop(min_heap)
71
- if len(min_heap)+len(max_heap) > 2*k:
+ if len(min_heap)+len(max_heap) > 2*k: # full delete
72
rebuild_heap(max_heap, to_remove, -1)
73
rebuild_heap(min_heap, to_remove, 1)
74
result.append(float(min_heap[0]) if k%2 else (min_heap[0]-max_heap[0])/2.0)
0 commit comments