-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48.Rotate_Image.cpp
More file actions
28 lines (26 loc) · 852 Bytes
/
Copy path48.Rotate_Image.cpp
File metadata and controls
28 lines (26 loc) · 852 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
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
recursionRotate(matrix, 0, matrix.size());
return;
}
void recursionRotate(vector<vector<int>>& matrix, int start, int length)
{
int endPos = start + length - 1;
if(length <= 1)
return;
else
{
for(int i = 0; i < length - 1; i++)
{
int tmp = matrix[start][start + i];
matrix[start][start + i] = matrix[endPos - i][start];
matrix[endPos - i][start] = matrix[endPos][endPos - i];
matrix[endPos][endPos - i] = matrix[start + i][endPos];
matrix[start + i][endPos] = tmp;
}
recursionRotate(matrix, start + 1, length - 2);
}
return;
}
};