Total Accepted: 62135
Total Submissions: 182151
Difficulty: Medium
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
将一个二维数组顺时针旋转90度 ;
先将行逆置,然后行列交换即可 ;
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
reverse(matrix.begin() , matrix.end()) ;
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] ) ;
}
};