Skip to content

Commit 49f8966

Browse files
committed
Runtime: 476 ms (Top 5.23%) | Memory: 135.2 MB (Top 5.23%)
1 parent ad73293 commit 49f8966

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
// Runtime: 476 ms (Top 5.23%) | Memory: 135.2 MB (Top 5.23%)
12
class Solution {
23
public boolean asteroidsDestroyed(int mass, int[] asteroids) {
34
PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a,b)->b-a);
45
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
5-
6+
67
for(int val:asteroids)
78
maxHeap.add(val);
8-
9+
910
long bigMass = mass;
10-
11+
1112
while(maxHeap.size()>0){
1213
int curr = maxHeap.poll();
13-
14+
1415
if(bigMass>=curr){
1516
bigMass+=curr;
1617
while(minHeap.size()>0 && bigMass>=minHeap.peek()){
@@ -21,7 +22,7 @@ public boolean asteroidsDestroyed(int mass, int[] asteroids) {
2122
minHeap.add(curr);
2223
}
2324
}
24-
25+
2526
return minHeap.size()==0 && maxHeap.size()==0;
2627
}
27-
}
28+
}

0 commit comments

Comments
 (0)