We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6fad07b commit e61ec21Copy full SHA for e61ec21
lcof2/剑指 Offer II 103. 最少的硬币数目/README.md
@@ -174,16 +174,16 @@ var coinChange = function (coins, amount) {
174
```swift
175
class Solution {
176
func coinChange(_ coins: [Int], _ amount: Int) -> Int {
177
-
178
var dp = [Int](repeating: amount + 1, count: amount + 1)
179
dp[0] = 0
180
+
181
for coin in coins {
+ if coin > amount { continue }
182
for j in coin...amount {
183
dp[j] = min(dp[j], dp[j - coin] + 1)
184
}
185
186
187
return dp[amount] > amount ? -1 : dp[amount]
188
189
0 commit comments