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

Commit8104620

Browse files
authored
Merge pull requestneetcode-gh#1042 from notauserx/48-Rotate-Image.cs
Create 48-Rotate-Image.cs
2 parents046034e +bfe5ff1 commit8104620

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎csharp/48-Rotate-Image.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
publicclassSolution{
2+
publicvoidRotate(int[][]matrix){
3+
(intleft,intright)=(0,matrix.Length-1);
4+
5+
while(left<right){
6+
varlimit=right-left;
7+
for(vari=0;i<limit;i++){
8+
(inttop,intbottom)=(left,right);
9+
10+
// save the top left position
11+
vartopLeft=matrix[top][left+i];
12+
13+
// put the bottom left value to the top left position
14+
matrix[top][left+i]=matrix[bottom-i][left];
15+
16+
// put the bottom right value to the bottom left position
17+
matrix[bottom-i][left]=matrix[bottom][right-i];
18+
19+
// put the top right value to the bottom right position
20+
matrix[bottom][right-i]=matrix[top+i][right];
21+
22+
// put the saved top left value to the top right position
23+
matrix[top+i][right]=topLeft;
24+
25+
26+
}
27+
28+
left++;
29+
right--;
30+
}
31+
32+
return;
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp