先沿对角线翻转,然后沿矩阵的y轴再翻转一次。
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
// Note: The Solution object is instantiated only once and is reused by each test case.
for(int i = 0; i < matrix.size(); i++)
for(int j = i+1; j < matrix[i].size(); j++)
swap(matrix[i][j], matrix[j][i]);
for(int i = 0; i < matrix.size(); i++)
for(int j = 0; j < matrix.size()/2; j++)
swap(matrix[i][j], matrix[i][matrix.size()-1-j]);
}
};