Skip to main content

867. Transpose Matrix

分析

简单~

题解

func transpose(matrix [][]int) [][]int {
n, m := len(matrix), len(matrix[0])
newMartix := make([][]int, m)
for i := range newMartix {
newMartix[i] = make([]int, n)
}

for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
newMartix[j][i] = matrix[i][j]
}
}
return newMartix
}