Skip to content

Instantly share code, notes, and snippets.

@myf
Created July 17, 2019 20:18
Show Gist options
  • Save myf/4cfb0d31ac3216070c918e194e3954d2 to your computer and use it in GitHub Desktop.
Save myf/4cfb0d31ac3216070c918e194e3954d2 to your computer and use it in GitHub Desktop.
class Solution:
def change(self, amount: int, coins: List[int]) -> int:
return self.cc(amount, coins,0, {})
def cc(self, amount, coins, i,cache):
if amount == 0 or i >= len(coins):
return 1
if amount < 0:
return 0
if (amount, i) not in cache:
cache[(amount, i)] = self.cc(amount - coins[i], coins, i, cache) + self.cc(amount, coins, i + 1, cache)
return cache[(amount,i)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment