My short Java solution


  • 2
    J

    public void rotate(int[][] matrix) {

            int n=matrix.length;
    	 //if(n==1)return;
    	 for(int i=0;i<n-i-1;i++)
    	 for(int j=i;j<n-1-i;j++)
    	 {
    		 int temp=matrix[i][j];
    		 matrix[i][j]=matrix[n-1-j][i];
    		 matrix[n-1-j][i]=matrix[n-i-1][n-1-j];
    		 matrix[n-i-1][n-1-j]=matrix[j][n-i-1];
    		 matrix[j][n-i-1]=temp;
    		 
    	 }
    }

Log in to reply
 

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