Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created April 12, 2021 16:38
Show Gist options
  • Save mvallebr/18322d993ae783ab7e8123b42206c479 to your computer and use it in GitHub Desktop.
Save mvallebr/18322d993ae783ab7e8123b42206c479 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:
scoins = sorted(coins, reverse=True)
@lru_cache
def dfs(amt, index):
if amt == 0: return 1
if amt < 0: return 0
return sum(dfs(amt - scoins[i], i) for i in range(index+1))
return dfs(amount, len(coins)-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment