Skip to content

Commit e61ec21

Browse files
authored
Update README.md
1 parent 6fad07b commit e61ec21

File tree

1 file changed

+3
-3
lines changed
  • lcof2/剑指 Offer II 103. 最少的硬币数目

1 file changed

+3
-3
lines changed

lcof2/剑指 Offer II 103. 最少的硬币数目/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ var coinChange = function (coins, amount) {
174174
```swift
175175
class Solution {
176176
func coinChange(_ coins: [Int], _ amount: Int) -> Int {
177-
178177
var dp = [Int](repeating: amount + 1, count: amount + 1)
179178
dp[0] = 0
180-
179+
181180
for coin in coins {
181+
if coin > amount { continue }
182182
for j in coin...amount {
183183
dp[j] = min(dp[j], dp[j - coin] + 1)
184184
}
185185
}
186-
186+
187187
return dp[amount] > amount ? -1 : dp[amount]
188188
}
189189
}

0 commit comments

Comments
 (0)