You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
从外圈往里旋转
void rotate(vector<vector<int> > &matrix) {
int size = matrix.size();
int left = 0, right = size-1; //从外往里,一圈圈的旋转
vector<vector<int>> tmp;
tmp = matrix;
while(left < right)
{
for(int i = left,j = right; i < right+1,j>left-1; i++,j--)
{
matrix[left][i] = tmp[j][left];
matrix[i][right] = tmp[left][i];
matrix[right][i] = tmp[j][right];
matrix[i][left] = tmp[right][i];
}
left++;
right--;
}
}