You are viewing a single comment's thread. Return to all comments →
using namespace std;
vector coinChangeGreedy(const vector& coins, int amount) { vector result(coins.size(),0); for(int i=coins.size()-1;i>=0;i--) { result[i] = amount/coins[i]; amount %= coins[i]; } return result; }
int main() { vector coins = {1,5,10,25}; int amount =47;
cout<<"Greedy Approach result :"<<endl; vector <int> resultgreedy = coinChangeGreedy(coins,amount); for(int i=0;i<resultgreedy.size();i++) { cout<<resultgreedy[i]<<" "; } cout<< endl; return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
The Coin Change Problem
You are viewing a single comment's thread. Return to all comments →
include
include
using namespace std;
vector coinChangeGreedy(const vector& coins, int amount) { vector result(coins.size(),0); for(int i=coins.size()-1;i>=0;i--) { result[i] = amount/coins[i]; amount %= coins[i]; } return result; }
int main() { vector coins = {1,5,10,25}; int amount =47;
}