Skip to content

Commit cda892a

Browse files
committed
Runtime: 1606 ms (Top 23.08%) | Memory: 137.1 MB (Top 30.77%)
1 parent f4d7ad6 commit cda892a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
// Runtime: 1606 ms (Top 23.08%) | Memory: 137.1 MB (Top 30.77%)
12
var halveArray = function(nums) {
23
const n = nums.length;
34
const maxHeap = new MaxPriorityQueue({ priority: x => x });
4-
5+
56
let startSum = 0;
6-
7+
78
for (const num of nums) {
89
maxHeap.enqueue(num);
910
startSum += num;
1011
}
11-
12+
1213
let currSum = startSum;
13-
14+
1415
let numberOfOperations = 0;
15-
16+
1617
while (currSum > startSum / 2) {
1718
const biggestNum = maxHeap.dequeue().element;
18-
19+
1920
const halfNum = biggestNum / 2;
20-
21+
2122
numberOfOperations += 1;
2223
currSum -= halfNum;
23-
24+
2425
maxHeap.enqueue(halfNum);
2526
}
26-
27+
2728
return numberOfOperations;
28-
};
29+
};

0 commit comments

Comments
 (0)