将指定范围内的整数打包为切片返回
// Range 将start到stop范围之间的整数作为切片返回
func Range(start, stop int) []int {
var result []int
result = append(result, start)
if stop >= start {
for {
if start == stop {
return result
}
start += 1
result = append(result, start)
}
}
for {
if start == stop {
return result
}
start -= 1
result = append(result, start)
}
}
网友评论