Skip to content

Commit

Permalink
Create 4_RotateMatrix90Deg.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
vibrantachintya committed Jan 2, 2022
1 parent e180732 commit 28bb263
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Arrays/4_RotateMatrix90Deg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix.size();
for (int i = 0; i < (n + 1) / 2; i ++) {
for (int j = 0; j < n / 2; j++) {
int temp = matrix[n - 1 - j][i];
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - j - 1];
matrix[n - 1 - i][n - j - 1] = matrix[j][n - 1 -i];
matrix[j][n - 1 - i] = matrix[i][j];
matrix[i][j] = temp;
}
}
}
};

0 comments on commit 28bb263

Please sign in to comment.