https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/
func findContinuousSequence(_ target: Int) -> [[Int]] {
var result = [[Int]]()
var l = 1
var r = 2
var sum = 0
while l < r {
sum = (l + r) * (r - l + 1) / 2
if sum == target {
result.append(createArr(l, r))
l = l + 1
} else if sum > target {
l = l + 1
} else if sum < target {
r = r + 1
}
}
return result
}
func createArr(_ start: Int, _ end: Int) -> [Int] {
var result = [Int]()
var startV = start
while startV <= end {
result.append(startV)
startV = startV + 1
}
return result
}
网友评论