文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix.size();
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
swap(matrix[i][j], matrix[j][i]);
}
}
for(int k = 0; k < n; k++) {
int i = 0;
int j = n - 1;
while(i < j) {
swap(matrix[k][i], matrix[k][j]);
i++;
j--;
}
}
}
private:
void swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
};