Coding · Medium · Pro
Rotate an n×n matrix 90 degrees clockwise in-place
CodingMatrixSenior
Approach
- Transpose the matrix, then reverse each row.
- Or rotate layer by layer in place for strict O(1) extra space.
Java Solution
Java
public void rotate(int[][] matrix) {
int n = matrix.length;…