换下顺序就是排列数??
func combinationSum4(_ nums: [Int], _ target: Int) -> Int {
var dp = Array.init(repeating: 0, count: target + 1)
dp[0] = 1
for i in 0...target {
for num in nums {
if i < num || dp[i] > Int.max - dp[i - num]{
continue
}
dp[i] += dp[i - num]
}
}
return dp.last!
}
网友评论