矩阵转置,A[i][j] 变成A[j][i] 比较简单,直接上代码了。
func transpose(A [][]int) [][]int {
B := make([][]int, len(A[0]))
for i := 0; i < len(A[0]); i++ {
B[i] = make([]int, len(A))
for j := 0; j < len(A); j++ {
B[i][j] = A[j][i]
}
}
return B
}
原文地址:https://blog.51cto.com/fulin0532/2432313
时间: 2024-10-07 14:51:13