Skip to content

Commit 1a3c208

Browse files
Update and rename RotateImage.cpp to medium-48-rotate_image.cpp
1 parent c93ead7 commit 1a3c208

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

Codes/RotateImage.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

Codes/medium-48-rotate_image.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
2+
3+
// You have to rotate the image in-place.
4+
5+
// So, you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
6+
7+
8+
9+
// Example 1:
10+
11+
// Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
12+
// Output: [[7,4,1],[8,5,2],[9,6,3]]
13+
14+
// Example 2:
15+
16+
// Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
17+
// Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
18+
19+
20+
class Solution {
21+
public:
22+
void rotate(vector<vector<int>>& matrix) {
23+
24+
int n=matrix.size();
25+
for(int i=0;i<n;i++)
26+
{
27+
for(int j=0;j<i;j++)
28+
{
29+
30+
swap(matrix[i][j],matrix[j][i]);
31+
}
32+
}
33+
for(int i = 0; i < n; ++i){
34+
reverse(matrix[i].begin(), matrix[i].end());
35+
}
36+
37+
}
38+
};

0 commit comments

Comments
 (0)