Skip to content

Commit db923f6

Browse files
48. Rotate Image (java)
1 parent 584bcb0 commit db923f6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public void rotate(int[][] matrix) {
3+
if(matrix==null) return;
4+
int n=matrix.length;
5+
for(int i=0;i<n;i++){
6+
for(int j=i;j<n;j++){
7+
int temp=matrix[i][j];
8+
matrix[i][j]=matrix[j][i];
9+
matrix[j][i]=temp;
10+
}
11+
}
12+
for(int i=0;i<n;i++){
13+
for(int j=0;j<n/2;j++){
14+
int temp = matrix[i][j];
15+
matrix[i][j] = matrix[i][matrix.length-1-j];
16+
matrix[i][matrix.length-1-j] = temp;
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)