• 26.2%

https://leetcode.com/problems/coin-change/#/description

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

Note:

You may assume that you have an infinite number of each kind of coin.

152ms, 44.44%, 180 / 180, April.27th, 2016

https://leetcode.com/discuss/76194/c-o-n-amount-time-o-amount-space-dp-solution

[C++] O(n * amount) time O(amount) space DP solution

https://discuss.leetcode.com/topic/32602/c-dp-solution-o-n-m-time-o-m-space

C++ dp solution, O(N * M) time, O(M) space

dp[i] means the solution of amount ‘i’. Initialise each element of the dp array to -1, then for each coin value c:

1). if i - c < 0, do nothing.

2). if i - c >= 0 and dp[i - c] != -1, means there is a solution of amount ‘i - c’, dp[i] = min(dp[i], dp[i - c] + 1)

https://discuss.leetcode.com/topic/32589/fast-python-bfs-solution

Fast Python BFS Solution

This solution is inspired by the BFS solution for problem Perfect Square. Since it is to find the least coin solution (like a shortest path from 0 to amount), using BFS gives results much faster than DP.

https://discuss.leetcode.com/topic/32743/clean-dp-python-code

Clean dp python code

Assume dp[i] is the fewest number of coins making up amount i, then for every coin in coins, dp[i] = min(dp[i - coin] + 1).

The time complexity is O(amount * coins.length) and the space complexity is O(amount)

https://discuss.leetcode.com/topic/33840/fast-python-branch-and-bound-solution-beaten-99-python-submissions

Fast python branch and bound solution, beaten 99% python submissions

308ms, 93.13%, 180 / 180, April.28th, 2016

https://leetcode.com/discuss/76737/clean-dp-python-code

solution 2:

1180ms, 180 / 180, April.28th, 2016

https://leetcode.com/discuss/76737/clean-dp-python-code