1+ COINS = (200 , 100 , 50 , 20 , 10 , 5 , 2 , 1 )
2+
13def ways_to_make_change (total : int ) -> int :
24 """
35 Given access to coins with the values 1, 2, 5, 10, 20, 50, 100, 200, returns a count of all of the ways to make the passed total value.
@@ -11,7 +13,6 @@ def ways_to_make_change_helper(total: int, coin_index: int, cache={}) -> int:
1113 """
1214 Helper function for ways_to_make_change to avoid exposing the coins parameter to callers.
1315 """
14- coins = (200 , 100 , 50 , 20 , 10 , 5 , 2 , 1 )
1516
1617 key = (total , coin_index )
1718
@@ -21,15 +22,16 @@ def ways_to_make_change_helper(total: int, coin_index: int, cache={}) -> int:
2122 if total == 0 :
2223 return 1
2324
24- if coin_index == len (coins ):
25+ if coin_index == len (COINS ):
2526 return 0
2627
27- coin = coins [coin_index ]
28+ coin = COINS [coin_index ]
2829
2930 if coin > total :
3031 ways = ways_to_make_change_helper (total , coin_index + 1 )
32+
3133 else :
32- ways = (ways_to_make_change_helper (total - coin , coin_index ) + ways_to_make_change_helper (total , coin_index + 1 ) )
34+ ways = (ways_to_make_change_helper (total - coin , coin_index )) + ways_to_make_change_helper (total , coin_index + 1 )
3335
3436 cache [key ] = ways
3537 return ways
0 commit comments