Under my umbrella.

SKII

Less is more.

力扣题解 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];
                }
            }
        }
    }
    
posted @ 2020-07-04 20:59  NLYang  阅读(89)  评论(0编辑  收藏  举报