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 ac3f601 commit 675c0dcCopy full SHA for 675c0dc
Medium/Maximum Ice Cream Bars.java
@@ -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