Matrix Rotation
MediumP1Coding
matrix is an n x n grid of integers. Rotate it 90 degrees clockwise, in place: modify the given matrix rather than returning a new one.
Example 1
- Input
- matrix = [[1,2,3],[4,5,6],[7,8,9]]
- Output
- [[7,4,1],[8,5,2],[9,6,3]]
Example 2
- Input
- matrix = [[1,2],[3,4]]
- Output
- [[3,1],[4,2]]
Example 3
- Input
- matrix = [[1]]
- Output
- [[1]]
Constraints
- n == matrix.length == matrix[i].length
- 1 <= n <= 20
- -1000 <= matrix[i][j] <= 1000
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.