NOTE
Rotate Image
LeetCode notes on rotating an n x n matrix 90 degrees clockwise.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Problem Description
Given an n x n two-dimensional matrix matrix representing an image, rotate the image 90 degrees clockwise.
2. Approach
3. Implementation
func rotate(matrix [][]int) {
n := len(matrix)
tmp := make([][]int, n)
for i := range tmp {
tmp[i] = make([]int, n)
}
for i, row := range matrix {
for j, v := range row {
tmp[j][n-i-1] = v
}
}
copy(matrix, tmp)
}
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub