blob: 10d06380438e8b435cc0f213b6d9b2ab4333ff76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include "leetcode.h"
class Solution {
public:
void rotate(vector<vector<int>> &matrix) {
int n = matrix.size(), depth = n / 2;
for (int i = 0; i < depth; i++) {
int len = n - 2 * i - 1, opp = n - 1 - i;
for (int j = 0; j < len; j++) {
int tmp = matrix[i][i + j];
matrix[i][i + j] = matrix[opp - j][i];
matrix[opp - j][i] = matrix[opp][opp - j];
matrix[opp][opp - j] = matrix[i + j][opp];
matrix[i + j][opp] = tmp;
}
}
}
};
|