标签:style blog color io ar java for sp div
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||matrix.length<=1)
{
return ;
}
int N=matrix.length-1;
for(int x=0;x<=N;x++)
{
for(int y=0;y<=x&&x+y<N;y++)
{
int p=matrix[x][y];
matrix[x][y]=matrix[N-y][x];
matrix[N-y][x]=matrix[N-x][N-y];
matrix[N-x][N-y]=matrix[y][N-x];
matrix[y][N-x]=p;
}
}
}
}标签:style blog color io ar java for sp div
原文地址:http://blog.csdn.net/jiewuyou/article/details/39958813