forked from deepaktalwardt/interview-prep-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48-rotate-image.cpp
More file actions
31 lines (24 loc) · 923 Bytes
/
48-rotate-image.cpp
File metadata and controls
31 lines (24 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int r_beg = 0;
int r_end = matrix.size() - 1;
int c_beg = 0;
int c_end = matrix[0].size() - 1;
while (r_beg <= r_end && c_beg <= c_end) {
for (int i = 0; i < c_end - c_beg; i++) {
int tmp1 = matrix[r_beg][c_beg + i];
int tmp2 = matrix[r_beg + i][c_end];
matrix[r_beg][c_beg + i] = matrix[r_end - i][c_beg];
matrix[r_beg + i][c_end] = tmp1;
tmp1 = matrix[r_end][c_end - i];
matrix[r_end][c_end - i] = tmp2;
matrix[r_end - i][c_beg] = tmp1;
}
r_beg++;
r_end--;
c_beg++;
c_end--;
}
}
};