Created
September 29, 2017 08:18
-
-
Save thundergolfer/a145886bc4905314383ea27da03fbc3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def coinProblem(coins, total): | |
dp = [0] * (total + 1) | |
coins.sort() | |
for subtotal in range(1, total + 1): | |
best = float('inf') | |
for c in coins: | |
if c <= subtotal: | |
option = 1 + dp[subtotal - c] | |
if option < best: | |
best = option | |
else: | |
break | |
dp[subtotal] = best | |
return dp[total] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment