LeetCode 518. Coin Change 2

1
2
3
4
5
6
7
8
9
10
11
12
int change(int amount, int* coins, int coinsSize) {
    int* dp=(int*)calloc(amount+1,sizeof(int));
    dp[0]=1;
   
    for(int i=0;i<coinsSize;++i){
        for(int j=coins[i];j<=amount;++j){
            dp[j]+=dp[j-coins[i]];
        }
    }
   
    return dp[amount];
}



Leave a Reply

Your email address will not be published. Required fields are marked *