Advertisement
gelita

count coins

Feb 11th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.31 KB | None | 0 0
  1. public static int coinSum(List<int> coins, int total)
  2.     {
  3.         var dp = new int[total + 1];
  4.         dp[0] = 1;
  5.  
  6.         for(int i = 0; i < coins.Count; i++)
  7.             for(int coin = coins[i]; coin < total + 1; coin++)
  8.                 dp[coin] += dp[coin - coins[i]];
  9.  
  10.         return dp[total];
  11.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement