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) {
if(matrix == null) return ;
int rows = matrix.length;
if(rows <= 1) return;
for(int left=0, right=rows-1; left<right; left++, right--){
for(int high=left, low=right; high<low; high++, low--){
int t = matrix[high][left];
matrix[high][left] = matrix[low][left];
matrix[low][left] = matrix[low][right];
matrix[low][right] = matrix[high][right];
matrix[high][right] = t;
}
}
}
}