Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions coin_change_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List

class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [0] * (amount + 1)

dp[0] = 1

for coin in coins:
for curr_amount in range(coin, amount + 1):
dp[curr_amount] += dp[curr_amount - coin]

return dp[amount]

# Time Complexity: O(amount * n), where n is the number of coins
# Space Complexity: O(amount)
18 changes: 18 additions & 0 deletions paint_house.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def minCost(self, costs: List[List[int]]) -> int:
if not costs:
return 0

red, blue, green = costs[0]

for i in range(1, len(costs)):
new_red = costs[i][0] + min(blue, green)
new_blue = costs[i][1] + min(red, green)
new_green = costs[i][2] + min(red, blue)

red, blue, green = new_red, new_blue, new_green

return min(red, blue, green)

# Time Complexity: O(n), where n is the number of houses
# Space Complexity: O(1)