1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @Title: 和为s的连续正数序列 (和为s的连续正数序列 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-26 12:08:25
// @Runtime: 0 ms
// @Memory: 2.1 MB
func findContinuousSequence(target int) [][]int {
	lo, hi, sum := 1, 1, 0
	res := make([][]int, 0)

	for lo <= target>>1 {
		if sum < target {
			sum += hi
            hi++
		} else if sum > target {
			sum -= lo
            lo++
		} else {
			got := make([]int, 0)
			for i := lo; i < hi; i++ {
				got = append(got, i)
			}
			res = append(res, got)

			sum -= lo
            lo++
		}
	}

	return res
}