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?
public class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length;
int[][] A = new int[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
A[i][j] = matrix[i][j];
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
matrix[i][j] = A[n-j-1][i];
}
}
}