48. Rotate Image

leetcode48

题目

解题思路

新建一个等大小的数组,然后换一种形式为原先的数组赋值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void rotate(int[][] matrix) {
int[][] tmp = new int[matrix.length][matrix.length];
for(int i=0;i<matrix.length;i++) {
for(int j=0;j<matrix.length;j++) {
tmp[i][j] = matrix[i][j];
}
}
for(int i=0;i<matrix.length;i++) {
for(int j=0;j<matrix.length;j++) {
matrix[j][matrix.length-i-1] = tmp[i][j];
}

}
}

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×