Skip to content

Commit

Permalink
Time: 549 ms (5.01%), Space: 76.3 MB (99.83%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Jan 6, 2023
1 parent 606bb62 commit dcd67fc
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions 1833-maximum-ice-cream-bars/1833-maximum-ice-cream-bars.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
class Solution {
public:
int maxIceCream(vector<int>& costs, int coins) {
int count = 0;
sort(costs.begin(),costs.end());
int cnt=0;
for(int i=0;i<costs.size();i++)
{
if(costs[i]<=coins)
{
cnt++;
coins=coins-costs[i];
}
else
{
return cnt;
}

for(int i=0;i<costs.size();i++){
if(costs[i]>coins)break;
coins -= costs[i];
count++;
}
return cnt;

return count;
}
};

0 comments on commit dcd67fc

Please sign in to comment.