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) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<vector<int> > result(matrix.size());
for(int col=0; col < matrix.size(); col++){
for(int row = matrix.size()-1; row >=0; row--){
result[col].push_back(matrix[row][col]);
}
}
matrix = result;
}
};