diff --git a/Coin Change II.py b/Coin Change II.py new file mode 100644 index 00000000..694d92c9 --- /dev/null +++ b/Coin Change II.py @@ -0,0 +1,19 @@ +class Solution: + def change(self, amount: int, coins: List[int]) -> int: + m=len(coins) + n=amount + + dp = [[0] * (n + 1) for _ in range(m + 1)] + + for i in range(1,m+1): + dp[i][0]=1 + print(dp) + + for i in range(1,m+1): + for j in range(1,n+1): + if j int: + n=len(costs) + + for i in range(n-2,-1,-1): + costs[i][0]=costs[i][0]+min(costs[i+1][1],costs[i+1][2]) + costs[i][1]=costs[i][1]+min(costs[i+1][0],costs[i+1][2]) + costs[i][2]=costs[i][2]+min(costs[i+1][1],costs[i+1][0]) + return min(costs[0][1],min(costs[0][0],costs[0][2])) \ No newline at end of file