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?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//先求转置.
void rotate(vector<vector<int> > &matrix) {
for (int i = 0; i != matrix.size();++i){
for (int j = i+1; j != matrix[0].size();++j)
{
swap(matrix[i][j], matrix[j][i]);
}
reverse(matrix[i].begin(), matrix[i].end());
}
}