diff --git a/Problem 22 - Paint House.py b/Problem 22 - Paint House.py new file mode 100644 index 00000000..b8fda91f --- /dev/null +++ b/Problem 22 - Paint House.py @@ -0,0 +1,20 @@ +# 256. Paint House + +# Time complexiety: O(3*n) +# Space complexiety: O(1) + +class Solution: + def minCost(self, costs: List[List[int]]) -> int: + minCost = min(costs[0][0],costs[0][1],costs[0][2]) + + for i in range(1,len(costs)): + # RED + costs[i][0] = costs[i][0] + min(costs[i-1][1],costs[i-1][2]) + # GREEN + costs[i][1] = costs[i][1] + min(costs[i-1][0],costs[i-1][2]) + # BLUE + costs[i][2] = costs[i][2] + min(costs[i-1][0],costs[i-1][1]) + + minCost = min(costs[i][0],costs[i][1],costs[i][2]) + + return minCost diff --git a/Problem 23 - Coin Change II.py b/Problem 23 - Coin Change II.py new file mode 100644 index 00000000..6d3824e7 --- /dev/null +++ b/Problem 23 - Coin Change II.py @@ -0,0 +1,21 @@ +# 518. Coin Change II + +# Time Complexity: O(n*m) +# Space Complexity: O(m) + +class Solution: + def change(self, amount: int, coins: List[int]) -> int: + if not coins: + return 0 + + n = len(coins) + dp = [0 for i in range(amount + 1)] + + dp[0] = 1 + + for i in range(1, n + 1): + for j in range(amount + 1): + if j >= coins[i-1]: + dp[j] = dp[j] + dp[j-coins[i-1]] + + return dp[amount] \ No newline at end of file diff --git a/Sample.java b/Sample.java deleted file mode 100644 index 1739a9cb..00000000 --- a/Sample.java +++ /dev/null @@ -1,7 +0,0 @@ -// Time Complexity : -// Space Complexity : -// Did this code successfully run on Leetcode : -// Any problem you faced while coding this : - - -// Your code here along with comments explaining your approach