力扣题解 48th 旋转图像
48th 旋转图像
-
找到变换规则
找到变换前的和变换后的矩阵的转移方程:before[i][j] == after[j][n-i-1]
class Solution { public void rotate(int[][] matrix) { int n = matrix.length; int[][] p = new int[n][n]; for(int i = 0; i < n; i++) p[i] = Arrays.copyOf(matrix[i], n); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { matrix[j][n-1-i] = p[i][j]; } } } }