Skip to content

Commit fe4d183

Browse files
author
Li Li
committed
add code of 48
1 parent 59ce74b commit fe4d183

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// clock-wise rotate,先对角对折, 再横向对折
2+
// anti-clockwise, reverse the step, 横向对折 -> 对角对折,
3+
public class Solution {
4+
public void Rotate(int[,] matrix) {
5+
int m = matrix.GetLength(0);
6+
int n = matrix.GetLength(1);
7+
// 先对角对折
8+
for (int i = 0; i < m; i++) {
9+
for (int j = i; j < n; j++) {
10+
int temp = matrix[i, j];
11+
matrix[i, j] = matrix[j, i];
12+
matrix[j, i] = temp;
13+
}
14+
}
15+
// 再横向对折
16+
for (int i = 0; i < m; i++) {
17+
for (int j = 0; j < n / 2; j++) {
18+
int temp = matrix[i, j];
19+
matrix[i, j] = matrix[i, n - j - 1];
20+
matrix[i, n - j - 1] = temp;
21+
}
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)