Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
22 lines (21 loc) · 851 Bytes

File metadata and controls

22 lines (21 loc) · 851 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package leetcode._48_;
class Solution { // 解决这个问题的关键就是知道,图像旋转90度是可以通过先对称镜像,然后对角线镜像可以得到旋转结果
public void rotate(int[][] matrix) {
// 首先垂直镜像反转
for (int j = 0; j < matrix.length / 2; j++) {
for (int i = 0; i < matrix.length; i++) {
int tmp = matrix[j][i];
matrix[j][i] = matrix[matrix.length - 1 - j][i];
matrix[matrix.length - 1 - j][i] = tmp;
}
}
// 然后按照对角线反转
for (int i = 0; i < matrix.length; i++) {
for (int j = i + 1; j < matrix.length; j++) {
int tmp = matrix[j][i];
matrix[j][i] = matrix[i][j];
matrix[i][j] = tmp;
}
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.