forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0048-rotate-image.c
More file actions
28 lines (22 loc) · 846 Bytes
/
0048-rotate-image.c
File metadata and controls
28 lines (22 loc) · 846 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
void rotate(int** matrix, int matrixSize, int* matrixColSize){
int left = 0;
int right = matrixSize - 1;
while (left < right) {
for (int i = 0; i < right - left; i++) {
int top = left;
int bottom = right;
// save the topLeft
int topLeft = matrix[top][left + i];
// move bottom left into top left
matrix[top][left + i] = matrix[bottom - i][left];
// move bottom right into bottom left
matrix[bottom - i][left] = matrix[bottom][right - i];
// move top right into bottom right
matrix[bottom][right - i] = matrix[top + i][right];
// move top left into top right
matrix[top + i][right] = topLeft;
}
right -= 1;
left += 1;
}
}