- 原地旋转
将正方形的数组切分成一个个圈,然后对这个圈进行移动
class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length;
for(int i = 0; i < n/2; i++){
rotate(matrix, i, n-1-i);
}
}
public void rotate(int[][] matrix, int a, int b){
if(a == b) return;
for(int i = 0; i < b-a; i++){
int t1 = matrix[a][a+i], t2 = matrix[a+i][b], t3 = matrix[b][b-i], t4 = matrix[b-i][a];
matrix[a][a+i] = t4; matrix[a+i][b] = t1; matrix[b][b-i] = t2; matrix[b-i][a] = t3;
}
}
}
标签:rotate,matrix,int,void,旋转,leetcode48,图像,public
From: https://www.cnblogs.com/xzh-yyds/p/16614539.html