mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 23:04:42 +01:00
20201223
This commit is contained in:
32
20201223/main.go
Normal file
32
20201223/main.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import "sort"
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func find(target int, candidates []int) [][]int {
|
||||
l := len(candidates)
|
||||
var ret [][]int
|
||||
sort.Ints(candidates)
|
||||
for k, n := range candidates {
|
||||
for j := 1; j < l-k-1; j++ {
|
||||
sum := n
|
||||
nums := []int{n}
|
||||
for i := k + j; i < l; i++ {
|
||||
num := candidates[i]
|
||||
sum += num
|
||||
if sum > target {
|
||||
break
|
||||
}
|
||||
nums = append(nums, num)
|
||||
if sum == target {
|
||||
ret = append(ret, nums)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user