Skip to content

Latest commit

 

History

History
17 lines (15 loc) · 433 Bytes

101.md

File metadata and controls

17 lines (15 loc) · 433 Bytes

Coin Change

LeetCode Link

 int coinChange(vector<int>& coins, int amount) {
    vector<int> dp(amount + 1, amount + 1);  
    dp[0] = 0; 

    for (int i = 1; i <= amount; ++i) {
        for (int coin : coins) {
            if (i >= coin) {
                dp[i] = min(dp[i], dp[i - coin] + 1);
            }
        }
    }

    return dp[amount] > amount ? -1 : dp[amount];
}