forked from neetcode-gh/leetcode
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0048-rotate-image.cs
34 lines (24 loc) · 1.15 KB
/
0048-rotate-image.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
publicclassSolution{
publicvoidRotate(int[][]matrix){
(intleft,intright)=(0,matrix.Length-1);
while(left<right){
varlimit=right-left;
for(vari=0;i<limit;i++){
(inttop,intbottom)=(left,right);
// save the top left position
vartopLeft=matrix[top][left+i];
// put the bottom left value to the top left position
matrix[top][left+i]=matrix[bottom-i][left];
// put the bottom right value to the bottom left position
matrix[bottom-i][left]=matrix[bottom][right-i];
// put the top right value to the bottom right position
matrix[bottom][right-i]=matrix[top+i][right];
// put the saved top left value to the top right position
matrix[top+i][right]=topLeft;
}
left++;
right--;
}
return;
}
}