一、题目
二、题解
将矩阵左右对称交换,然后按照副对角线交换即可
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
for (int l = 0, r = matrix.size() - 1; l < r; l++, r--)
for (int i = 0; i < matrix.size(); i++)
swap(matrix[i][l], matrix[i][r]);
for (int i = 0; i < matrix.size(); i++)
for (int j = 0; j < matrix.size(); j++)
if (i >= matrix.size() - j)
swap(matrix[i][j], matrix[matrix.size() - j - 1][matrix.size() - i - 1]);
}
};