package main
import "log"
func main() {
log.Println(GroupRanges(0, 3, 6))
}
// 根据数量大小返回步长的数据组
func GroupRanges(first, step, target int) [][]int {
if step == 0 {
panic("group ranges step can't eq zero")
}
if first > target {
panic("first can't gt target")
}
if first+step >= target {
return [][]int{[]int{first, target}}
}
return append([][]int{[]int{first, first + step}}, GroupRanges(first+step, step, target)...)
}
网友评论