标签:ber 切片 [] 指定 == span 不可 numbers 传递
数组:
a := [...]int{1,2,3} a := [3]int{1,2,3}
切片:
a:= []int{1,2,3} a := make([]int, 5) a := make([]int, 5, 10)
numbers2 := [...]int{1, 2, 3, 4, 5, 6} maxIndex2 := len(numbers2) - 1 for i, e := range numbers2 { if i == maxIndex2 { numbers2[0] += e } else { numbers2[i+1] += e } } fmt.Println(numbers2) numbers3 := []int{1, 2, 3, 4, 5, 6} maxIndex3 := len(numbers3) - 1 for i, e := range numbers3 { if i == maxIndex3 { numbers3[0] += e } else { numbers3[i+1] += e } } fmt.Println(numbers3)
输出:
[7 3 5 7 9 11] [22 3 6 10 15 21]
标签:ber 切片 [] 指定 == span 不可 numbers 传递
原文地址:https://www.cnblogs.com/TimLiuDream/p/9898186.html