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?
这题好像很简单,难点是不是利用常量额外空间?
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
int n = matrix.size();
vector<vector <int> > matrixtmp(n ,vector<int>(n));
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j ++)
{
matrixtmp[j][n-i-1] = matrix[i][j];
}
}
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j ++)
{
matrix[i][j] = matrixtmp[i][j];
}
}
}
};