My simple Javascript solution


  • 0
    K
    var coinChange = function(coins, amount) {
    var dp=new Array(amount+1);
    dp.fill(Number.MAX_VALUE-1);
    dp[0]=0;
    for(var i=1;i<=amount;i++)
    {
        for(var j=0;j<coins.length;j++)if(coins[j]<=i){
            dp[i]=Math.min(dp[i-coins[j]]+1, dp[i]);
        }
    
    }
       return dp[amount]==Number.MAX_VALUE-1 ? -1:dp[amount];
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.