48.旋转图像

秋招未止脚步不止,大厂,我一定要上大厂!

题目链接

. - 力扣(LeetCode)

自己的思路

感觉好难,想不出来.

噫噫噫,我想着想着又想出来了。

//发现规律了,先左右对称, 再将坐标i,j变成(n-j, n-i)

好!

java 复制代码
class Solution {
    public void rotate(int[][] matrix) {
        //发现规律了,先左右对称, 再将坐标i,j变成(n-j, n-i)
        int len1 = matrix.length;
        
        for(int i =0; i < len1; i++){
            for(int j = 0; j < len1/2; j++){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][len1 - j - 1];
                matrix[i][len1 - j - 1] = temp;
            }
        }
        len1 --;
        for(int i = 0; i <= len1; i++){
            for(int j = 0; j < len1 - i; j ++ ){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[len1 - j][len1 - i];
                matrix[len1 - j][len1 - i] = temp;
            }
        }
    }
}

过,下一题!

相关推荐
祖力558 小时前
Linux应用软件编程:目录IO与framebuffer
linux·运维·算法·framebuffer·目录io
名字还没想好☜9 小时前
Go 用 slices/maps 标准库泛型函数:告别手写 Contains、Sort、去重(Go 1.21)
开发语言·后端·算法·golang·go
地平线开发者9 小时前
【模型轻量化专题】深度学习模型为什么需要轻量化
算法
_Narcissus_9 小时前
链表算法题和静态链表
数据结构·c++·笔记·算法·链表·ai·力扣
Lyyaoo.9 小时前
【普通数组】【中等】除了自身以外数组的乘积
数据结构·算法·leetcode
threerocks9 小时前
《The AI-Native SDLC Playbook》万字拆解
算法·aigc·ai编程
夏玉林的学习之路10 小时前
算法8.环形队列
算法
O。O蛋黄酥啊10 小时前
GraphRAG 和 LightRAG 详解与对比
人工智能·python·算法·rag·graphrag·lightrag
Σίσυφος190010 小时前
depth_from_focus 详解
算法
疯狂打码的少年11 小时前
【数据结构】八大排序算法对比总结(时间/空间/稳定性)
数据结构·笔记·算法