Rotate Image
Rotate a square matrix clockwise by 90 degrees in place. Return nothing; use constant auxiliary space.
Example 1
0,01
0,12
1,03
1,14
matrix = [[1,2],[3,4]][[3,1],[4,2]]Explanation
Each (r,c) moves to (c,1-r), producing rows [3,1],[4,2].
Example 2
0,01
0,12
0,23
1,04
1,15
1,26
2,07
2,18
2,29
matrix = [[1,2,3],[4,5,6],[7,8,9]][[7,4,1],[8,5,2],[9,6,3]]Explanation
Column 1,4,7 becomes row 7,4,1; the other columns rotate similarly.
Example 3
0,05
matrix = [[5]][[5]]Explanation
A 1-by-1 matrix stays unchanged.
Constraints
- 1 <= side length <= 20
- Entries are signed integers
Function contract
rotateArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,2],[3,4]]