Skip to content

Commit 1a8d227

Browse files
committed
fix Combination Sum
1 parent eed0990 commit 1a8d227

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

go/combination_sum.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//lint:file-ignore U1000 Ignore all unused code
22
package main
33

4-
import "sort"
5-
64
func combinationSum_dp(candidates []int, target int) [][]int {
75
combinationsGroups := make([][][]int, target+1)
86
combinationsGroups[0] = [][]int{{}}
@@ -19,7 +17,6 @@ func combinationSum_dp(candidates []int, target int) [][]int {
1917
}
2018

2119
func combinationSum_backtracking_stack(candidates []int, target int) [][]int {
22-
sort.Ints(candidates)
2320
combinations := [][]int{}
2421
type state struct {
2522
combination []int
@@ -37,7 +34,7 @@ func combinationSum_backtracking_stack(candidates []int, target int) [][]int {
3734
for i := current.index; i < len(candidates); i++ {
3835
newSum := current.sum + candidates[i]
3936
if newSum > target {
40-
break
37+
continue
4138
}
4239
newCombination := append([]int{}, current.combination...)
4340
newCombination = append(newCombination, candidates[i])

0 commit comments

Comments
 (0)