lc-go/solutions/0/q48/solution.go
2026-01-17 12:51:40 +09:00

21 lines
364 B
Go

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