Skip to content

Instantly share code, notes, and snippets.

@thundergolfer
Created September 29, 2017 08:18
Show Gist options
  • Save thundergolfer/a145886bc4905314383ea27da03fbc3e to your computer and use it in GitHub Desktop.
Save thundergolfer/a145886bc4905314383ea27da03fbc3e to your computer and use it in GitHub Desktop.
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