Skip to content

Commit adf6d13

Browse files
Added solution
1 parent 414c34b commit adf6d13

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

rotate_image.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
void rotate(vector<vector<int>>& matrix) {
4+
int N = matrix.size();
5+
6+
//1. transpose matrix
7+
for(int i=0; i<matrix.size(); i++){
8+
for(int j=0; j<i; j++){
9+
swap(matrix[i][j], matrix[j][i]);
10+
}
11+
}
12+
13+
//2.swap columns with 2 pointer approach
14+
15+
for(int i=0; i<N; i++){
16+
reverse(matrix[i].begin(), matrix[i].end());
17+
}
18+
}
19+
};

0 commit comments

Comments
 (0)