8000 2 · javasharper/leetcode@d33343a · GitHub
[go: up one dir, main page]

Skip to content

Commit d33343a

Browse files
committed
2
1 parent ea06548 commit d33343a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

RotateImage/RotateImage.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
void rotate(vector<vector<int>>& matrix) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
int n = matrix.size();
8+
for (int i = 0; i < n / 2; i++) {
9+
for (int j = i; j < n - 1 - i; j++) {
10+
int x = matrix[i][j];
11+
matrix[i][j] = matrix[n-1-j][i];
12+
matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
13+
matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
14+
matrix[j][n-1-i] = x;
15+
}
16+
}
17+
}
18+
};

0 commit comments

Comments
 (0)
0