You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

class Solution {
public void rotate(int[][] matrix) {
int N = matrix.length;
// 先对矩阵转置
for(int y = 0; y < N; y ++)
{
for(int x = y; x < N; x++)
{
int t = matrix[y][x];
matrix[y][x] = matrix[x][y];
matrix[x][y] = t;
}
}
// 然后做一次左右对称
for(int y = 0; y < N; y ++)
{
for(int x = 0; x < N/2; x++)
{
int t = matrix[y][x];
matrix[y][x] = matrix[y][N-1-x];
matrix[y][N-1-x] = t;
}
}
}
}
class Solution {
public void rotate(int[][] matrix) {
int Len = matrix.length;
for(int i=0; i<Len/2; i++){
for (int j=i; j<Len-i-1; j++){
rotating(matrix,i,j, Len);
}
}
}

public void rotating(int[][]matrix, int i,int j, int Len){
int temp;
temp=matrix[i][j];
matrix[i][j]=matrix[Len-1-j][i];
matrix[Len-1-j][i]=matrix[Len-1-i][Len-1-j];
matrix[Len-1-i][Len-1-j]=matrix[j][Len-1-i];
matrix[j][Len-1-i]=temp;
}
}