Simple and easy java in-place solution


  • -1
    M
    public void rotate(int[][] matrix) {
            int l = matrix.length;
            int[][] visit = new int[l][l];
            for(int i = 0; i < l; i++){
                for(int j = 0; j < l; j++){
                    if(visit[i][j] == 0){
                        int temp = matrix[i][j];
                        matrix[i][j] = matrix[j][l-i-1];
                        matrix[j][l-i-1] = temp;
                        visit[i][j] = 1;
                        visit[j][l-i-1] = 1;
                    }
                }
            }
        }

Log in to reply
 

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