标签:ola make pre pack port package length 获取 end
在做一些算法题时经常要用到二维切片,所以这里整理一下创建二维切片的方法,方便日后查阅。
package main
import "fmt"
func main() {
// 初始化方法1
row, column := 3, 4
var answer [][]int
for i := 0; i < row; i++ {
inline := make([]int, column)
answer = append(answer, inline)
}
fmt.Println(answer)
// 初始化方法2
answer1 := make([][]int, row)
for i := range answer1 {
answer1[i] = make([]int, column)
}
fmt.Println(answer1)
}
获取二维切片的行与列:
rows := array.length // 行数
columns := array[0].length // 列数
欢迎访问我的个人网站:
李培冠博客:lpgit.com
标签:ola make pre pack port package length 获取 end
原文地址:https://www.cnblogs.com/lpgit/p/13423477.html