Skip to main content
PreparationZone Logo
PreparationZone
Back to Coding

Coding · Medium · Pro

Rotate image 90 degrees clockwise in-place

CodingMatrixSenior
Model answerPreview

Approach

  • Transpose the matrix.
  • Reverse each row.

Java Solution

Java
void rotate(int[][] m) {
    int n = m.length;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j <…