MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / rotate

Function rotate

rotate_image_48/solution.go:3–18  ·  view source on GitHub ↗
(matrix [][]int)

Source from the content-addressed store, hash-verified

1package rotate_image_48
2
3func rotate(matrix [][]int) {
4 // transpose the matrix in-place, by turning it's rows into columns
5 for i := 0; i < len(matrix); i++ {
6 for j := i; j < len(matrix[i]); j++ {
7 matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
8 }
9 }
10
11 // reverse each row of the transposed matrix to get the 90deg rotated matrix
12 for i := 0; i < len(matrix); i++ {
13 for j := 0; j < len(matrix[i])/2; j++ {
14 matrix[i][j], matrix[i][len(matrix[i])-1-j] =
15 matrix[i][len(matrix[i])-1-j], matrix[i][j]
16 }
17 }
18}

Callers 1

Test_rotateFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_rotateFunction · 0.68