Skip to content

Commit

Permalink
Create 2706. Buy Two Chocolates (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 20, 2023
2 parents a3785dd + 60ada73 commit 7395dba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 2706. Buy Two Chocolates
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int buyChoco(vector<int>& prices, int money) {
auto it = min_element(prices.begin(),prices.end());
int index = it - prices.begin();
int mini1 = prices[index];
// cout << mini1 << endl;
prices.erase(prices.begin()+index);
it = min_element(prices.begin(),prices.end());
index = it - prices.begin();
int mini2 = prices[index];
// cout << mini2 << endl;

int sum = mini1 + mini2;
// cout << sum << endl;
if(sum <= money) return money - sum;
return money;
}
};

0 comments on commit 7395dba

Please sign in to comment.