Simple Java Solution


  • 1
    C
    public class Solution {
        public void rotate(int[][] matrix) {
         int n = matrix.length;
         int[][] rotatedMatrix = new int[n][n];
         for(int i = 0; i < n; i++){
             for(int j = 0; j < n; j++){
                 rotatedMatrix[i][j] = matrix[(n-1) - j][i];
             }
         }
         
        for(int i = 0; i < n; i++){
             for(int j = 0; j < n; j++){
                 matrix[i][j] = rotatedMatrix[i][j];
             }
         }
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.