首页 > 其他 > 详细

力扣题解 48th 旋转图像

时间:2020-07-04 21:46:51      阅读:41      评论:0      收藏:0      [点我收藏+]

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];
                }
            }
        }
    }
    

力扣题解 48th 旋转图像

原文:https://www.cnblogs.com/fromneptune/p/13236611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!