Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created April 12, 2021 16:37
Show Gist options
  • Save mvallebr/b48de95d4284b09d29aa0d050b5c6042 to your computer and use it in GitHub Desktop.
Save mvallebr/b48de95d4284b09d29aa0d050b5c6042 to your computer and use it in GitHub Desktop.
from functools import lru_cache
class Solution:
def change(self, amount: int, coins: List[int]) -> int:
@lru_cache
def dfs(amt):
if amt == 0: return 1
if amt < 0: return 0
return sum(dfs(amt - coins[i]) for i in range(len(coins)))
return dfs(amount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment