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 1a3da38 commit 8b115c7Copy full SHA for 8b115c7
lcof2/剑指 Offer II 104. 排列的数目/README.md
@@ -147,16 +147,16 @@ func combinationSum4(nums []int, target int) int {
147
class Solution {
148
func combinationSum4(_ nums: [Int], _ target: Int) -> Int {
149
var dp = [Int](repeating: 0, count: target + 1)
150
- dp[0] = 1
+ dp[0] = 1
151
152
for i in 1...target {
153
for num in nums {
154
- if i >= num {
+ if i >= num, dp[i] <= Int.max - dp[i - num] {
155
dp[i] += dp[i - num]
156
}
157
158
159
-
+
160
return dp[target]
161
162
0 commit comments