Skip to content

Commit 2ee30f9

Browse files
committed
rotate image
1 parent cbbe739 commit 2ee30f9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Rotate Image.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Rotate 90 degree
2+
// what about 180 degree?
3+
// 1 2 => 4 2 => 3 1
4+
// 3 4 => 3 1 => 4 2
5+
class Solution {
6+
public:
7+
void rotate(vector<vector<int> > &matrix) {
8+
int n = matrix.size();
9+
for(int i = 0; i < n; i++)
10+
for(int j = 0; j < n - i; j++)
11+
swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]);
12+
13+
for(int i = 0; i < n / 2; i++)
14+
for(int j = 0; j < n; j++)
15+
swap(matrix[i][j], matrix[n -1 -i][j]);
16+
}
17+
};

0 commit comments

Comments
 (0)