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?
图像顺时针90度旋转
1.找规律:发现 可以将 matrix[i][j]=maxtrix[n-1-j][i]
先写了一个本办法,有用了一个矩阵
public class Solution {
public void rotate(int[][] matrix) {
int n =matrix.length;
int[][] b =new int[n][n];
for(int i=0;i<=n-1;i++)
{
for(int j=0;j<=n-1;j++)
{
b[i][j]=matrix[n-1-j][i];
}
}
for(int i=0;i<=n-1;i++)
{
for(int j=0;j<=n-1;j++)
{
matrix[i][j]=b[i][j];
}
}
}
}