-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 549 ms (5.01%), Space: 76.3 MB (99.83%) - LeetHub
- Loading branch information
1 parent
606bb62
commit dcd67fc
Showing
1 changed file
with
6 additions
and
15 deletions.
There are no files selected for viewing
21 changes: 6 additions & 15 deletions
21
1833-maximum-ice-cream-bars/1833-maximum-ice-cream-bars.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |