MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getHeap

Method getHeap

javascript/0295-find-median-from-data-stream.js:24–29  ·  view source on GitHub ↗
(num, { maxHeap, minHeap } = this)

Source from the content-addressed store, hash-verified

22 }
23
24 getHeap(num, { maxHeap, minHeap } = this) {
25 const isFirst = maxHeap.isEmpty();
26 const isGreater = num <= this.top(maxHeap);
27 const isMaxHeap = isFirst || isGreater;
28 return isMaxHeap ? maxHeap : minHeap;
29 }
30
31 rebalance({ maxHeap, minHeap } = this) {
32 const canShiftMax = minHeap.size() + 1 < maxHeap.size();

Callers 1

addNumMethod · 0.95

Calls 2

topMethod · 0.95
isEmptyMethod · 0.45

Tested by

no test coverage detected