以下code(39号问题)我可以在leetcode playground直接运行出正确的结果。但是submit 代码的时候总是提示我失败在这个输入。 我之前提交combination问题的时候也是同样的问题。可以在别处正常通过测试用例,但是submit就失败了。到底是我哪里粗心了,或者是leetcode的问题?
提前谢谢老师,给老师添麻烦了!
插一个题外话,我想买老师的新课听听红黑树等高级知识。但是和已经买的两门有很多重复的课程。有针对老学员的优惠吗?
package main
import (
"fmt"
)
var result [][]int
func combineSum(candidates []int, target int, start int, c []int) {
if target <= 0 {
if target == 0 {
q := make([]int, len(c))
copy(q, c)
result = append(result, q)
}
return
}
for _, v := range candidates[start:] {
c = append(c, v)
combineSum(candidates, target-v, start, c)
c = c[:len(c)-1]
start++
}
}
func combinationSum(candidates []int, target int) [][]int {
if len(candidates) == 0 {
return result
}
var c []int
combineSum(candidates, target, 0, c)
return result
}
func main() {
fmt.Printf("The result of combination sum: %v", combinationSum([]int{42, 26, 36, 38, 35, 41, 20, 47, 45, 23, 33, 39, 25, 43, 29, 31, 28, 48, 21, 46, 22, 30, 37, 32, 44, 40}, 55))
}