Advertisement
Guest User

Code Change 2 python3

a guest
Sep 5th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Solution:
  2. def change(self, amount: int, coins: List[int], vals={}) -> int:
  3. if coins == []:
  4. return 0
  5.  
  6. if vals.get((coins[0], amount)) is not None:
  7. return vals.get((coins[0], amount))
  8.  
  9. multiple = 0
  10. coin_val = coins[0]
  11. answer = 1 if amount % coin_val == 0 else 0
  12.  
  13. while coin_val * multiple < amount:
  14. new_amount = amount - (coin_val*multiple)
  15. answer += self.change(new_amount, coins[1:], vals)
  16. multiple += 1
  17.  
  18. vals[(coin_val, amount)] = answer
  19.  
  20. return answer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement