【Leetcode--旋转矩阵】

解题思路:先进行矩阵上下交换,接着对矩阵进行主对角线交换,就可以从上述左图变换为右图。

class Solution {
    public void rotate(int[][] matrix) {
        //上下交换
        for(int i = 0 ; i<matrix.length/2;i++){
            int[] temp = matrix[i];
            matrix[i] = matrix[matrix.length-i-1];
            matrix[matrix.length-i-1] =temp; 
        }
        //对角交换
        for(int i = 0 ; i<matrix.length;i++){
            for(int j = i+1 ; j<matrix.length;j++){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
    }
}

相关推荐

  1. LeetCode热题100】【矩阵旋转图像

    2024-07-16 07:48:03       30 阅读
  2. 旋转矩阵旋转向量

    2024-07-16 07:48:03       41 阅读
  3. 旋转图像【矩阵

    2024-07-16 07:48:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 07:48:03       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 07:48:03       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 07:48:03       62 阅读
  4. Python语言-面向对象

    2024-07-16 07:48:03       72 阅读

热门阅读

  1. 微服务治理新篇章:Eureka中细粒度策略管理实现

    2024-07-16 07:48:03       24 阅读
  2. Lua 运算符

    2024-07-16 07:48:03       19 阅读
  3. Android 14 开机时间优化措施

    2024-07-16 07:48:03       22 阅读
  4. OpenCV 轮廓检测

    2024-07-16 07:48:03       28 阅读
  5. Jupyter Lab 使用

    2024-07-16 07:48:03       24 阅读
  6. python笔记(转存ipynb)------1

    2024-07-16 07:48:03       21 阅读
  7. 《读书笔记-骆驼祥子》

    2024-07-16 07:48:03       23 阅读
  8. sql面试题

    2024-07-16 07:48:03       24 阅读
  9. 开发指南048-mysql设置

    2024-07-16 07:48:03       28 阅读
  10. Web 中POST为什么会发送两次请求

    2024-07-16 07:48:03       27 阅读
  11. Sqlmap中文使用手册 - Injection模块参数使用

    2024-07-16 07:48:03       26 阅读