lc-go/solutions/0/q48/solution.go

22 lines
449 B
Go

// Package q48 implements a solution for https://leetcode.com/problems/rotate-image/
package q48
func rotateCell(matrix [][]int, x, y int) {
t := matrix[y][x]
for range 4 {
nextX, nextY := len(matrix)-1-y, x
matrix[nextY][nextX], t = t, matrix[nextY][nextX]
x, y = nextX, nextY
}
}
func rotate(matrix [][]int) {
w := len(matrix)
for y := range w / 2 {
for x := y; x < w-y-1; x++ {
rotateCell(matrix, x, y)
}
}
}
var _ = rotate