以前在acwing看过,但是找不到视频了,大家知道的可以告诉我呵呵,就是左右旋转,然后沿45度对角线再翻转;
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix[0].size();
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n / 2; j ++ )
{
swap(matrix[i][j], matrix[i][n - 1 - j]);
}
}
for (int i = 0; i < n - 1; i ++ )
{
for (int j = 0; j < n - 1 - i; j ++ )
{
swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]);
}
}
}
};