Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 10, 2023
1 parent 5cbab71 commit c93d2cc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions leetcode/867.TransposeMatrix/transposeMatrix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
)

func transpose(matrix [][]int) [][]int {
m := len(matrix)
n := len(matrix[0])
result := make([][]int, n)
for i := 0; i < n; i++ {
result[i] = make([]int, m)
for j := 0; j < m; j++ {
result[i][j] = matrix[j][i]
}
}
return result
}

func main() {
matrix := [][]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
fmt.Println(transpose(matrix))
}

0 comments on commit c93d2cc

Please sign in to comment.