Created
July 17, 2019 20:18
-
-
Save myf/4cfb0d31ac3216070c918e194e3954d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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