Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit46ee550

Browse files
committed
rotate
1 parentc874e3e commit46ee550

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎array/Rotate.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
packageAlgorithms.array;
2+
3+
publicclassRotate {
4+
publicvoidrotate(int[][]matrix) {
5+
if (matrix ==null ||matrix.length ==0
6+
||matrix[0].length ==0) {
7+
return;
8+
}
9+
10+
intn =matrix.length;
11+
inttop =0,down =n -1,left =0,right =n -1;
12+
13+
while (n >1) {
14+
for (inti =0;i <n -1;i++) {
15+
inttmp =matrix[top][left +i];
16+
// 另上边等于左边
17+
matrix[top][left +i] =matrix[down -i][left];
18+
19+
// 另左边等于下边
20+
matrix[down -i][left] =matrix[down][right -i];
21+
22+
// 另下边等于右边
23+
matrix[down][right -i] =matrix[top +i][right];
24+
25+
// 另右边等于上边
26+
matrix[top +i][right] =tmp;
27+
}
28+
top++;
29+
right--;
30+
left++;
31+
down--;
32+
33+
n -=2;
34+
}
35+
36+
return;
37+
}
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp