image_2021-11-15_01-43-45.png
30.7 KB
#medium
#N1833. Maximum Ice Cream Bars
problem link
#solution
#N1833. Maximum Ice Cream Bars
problem link
#solution
class Solution {
public int maxIceCream(int[] costs, int coins) {
int count=0;
Arrays.sort(costs);
for(int i=0; i<costs.length&&coins>0; i++){
if(costs[i]<=coins){
coins-=costs[i];
count++;
}
}
return count;
}
}