chore:clean up

Signed-off-by: qinguoyi <1532979219@qq.com>
This commit is contained in:
qinguoyi 2024-08-07 22:17:28 +08:00
parent a98041281d
commit 2db9dc4811
1 changed files with 12 additions and 17 deletions

View File

@ -158,16 +158,14 @@ func findFeasiblePaths(groups []*GroupInfo, minConstraint, maxConstraint, target
}) })
} }
if len(groups) < minConstraint {
return
}
if len(groups) == minConstraint {
var sum int
rootPath := new(dfsPath) rootPath := new(dfsPath)
for _, i := range groups { var dfsFunc func(int, int)
sum += i.value dfsFunc = func(sum, begin int) {
rootPath.enqueue(i) // directly check the sum
if len(groups) == minConstraint {
for _, group := range groups {
sum += group.value
rootPath.enqueue(group)
} }
if sum >= target { if sum >= target {
paths = append(paths, rootPath.next()) paths = append(paths, rootPath.next())
@ -175,9 +173,6 @@ func findFeasiblePaths(groups []*GroupInfo, minConstraint, maxConstraint, target
return return
} }
rootPath := new(dfsPath)
var dfsFunc func(int, int)
dfsFunc = func(sum, begin int) {
if sum >= target && rootPath.length() >= minConstraint && rootPath.length() <= maxConstraint { if sum >= target && rootPath.length() >= minConstraint && rootPath.length() <= maxConstraint {
paths = append(paths, rootPath.next()) paths = append(paths, rootPath.next())
return return