diff --git a/Coin Change II.py b/Coin Change II.py new file mode 100644 index 00000000..2331c997 --- /dev/null +++ b/Coin Change II.py @@ -0,0 +1,21 @@ +class Solution: + def change(self, amount: int, coins: List[int]) -> int: + if coins == None or len(coins)== 0: + return 0 + + n = len(coins) + + dp = [[0]*(amount+1)]*(n+1) + for i in range(n+1): + dp[i][0] = 1 + + for i in range(1,n+1): + for j in range(1,amount+1): + if j< coins[i-1]: + dp[i][j] = dp[i-1][j] + else: + dp[i][j]= dp[i-1][j] + dp[i][j-coins[i-1]] + + + + return dp[n][amount] \ No newline at end of file diff --git a/Paint House.py b/Paint House.py new file mode 100644 index 00000000..e1bed92b --- /dev/null +++ b/Paint House.py @@ -0,0 +1,30 @@ +class Solution: + def minCost(self, costs: List[List[int]]) -> int: + + if costs == None or len(costs) == 0: + return 0 + + n = len(costs) + + + + dp = [[0 for i in range(3)] for i in range(n)] + # dp = [([0] * 3)] * n + dp[n-1][0] = costs[n-1][0] + dp[n-1][1] = costs[n-1][1] + dp[n-1][2] = costs[n-1][2] + # print(dp) + + for i in range(n-2, -1, -1): + dp[i][0] = costs[i][0] + min(dp[i+1][1],dp[i+1][2]) + dp[i][1] = costs[i][1] + min(dp[i+1][0],dp[i+1][2]) + dp[i][2] = costs[i][2] + min(dp[i+1][0],dp[i+1][1]) + + # print(dp) + return min(dp[0][0],dp[0][1],dp[0][2]) + + + + + + \ No newline at end of file