版权声明:原创勿转 https://cloud.tencent.com/developer/article/1420470
思路
直接交换对应位置上的值
code
代码语言:javascript复制func transpose(A [][]int) [][]int {
m := len(A)
n := len(A[0])
ans := make([][]int, n)
for k := range ans {
ans[k] = make([]int, m)
}
for r := 0; r < m; r {
for c := 0; c < n; c {
ans[c][r] = A[r][c]
}
}
return ans
}