Skip to content

Commit 675c0dc

Browse files
authored
Added Maximum Ice Cream Bars.java
1 parent ac3f601 commit 675c0dc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Medium/Maximum Ice Cream Bars.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maxIceCream(int[] costs, int coins) {
3+
PriorityQueue<Integer> pq = new PriorityQueue<>();
4+
pq.addAll(Arrays.stream(costs).boxed().collect(Collectors.toList()));
5+
int icecreamCount = 0;
6+
while (!pq.isEmpty() && (coins - pq.peek()) >= 0) {
7+
coins -= pq.poll();
8+
icecreamCount++;
9+
}
10+
return icecreamCount;
11+
}
12+
}

0 commit comments

Comments
 (0)