美文网首页
根据数量大小返回步长的数据组

根据数量大小返回步长的数据组

作者: funcx | 来源:发表于2019-08-13 16:35 被阅读0次
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)...)
}

相关文章

网友评论

      本文标题:根据数量大小返回步长的数据组

      本文链接:https://www.haomeiwen.com/subject/hyebjctx.html