48. 旋转图像(LeetCode中等)(常识顺时针90旋转)
48. 旋转图像
先沿着副对角线翻转,然后水平翻转
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix.size();
for(int i = 0; i < n; ++i){
for(int j = 0; j < i; ++j){
swap(matrix[i][j], matrix[j][i]);
}
}
for(int i = 0; i < n; ++i){
for(int j = 0, k = n - 1; j < k; ++j, --k){
swap(matrix[i][j], matrix[i][k]);
}
}
return ;
}
};

浙公网安备 33010602011771号