【hot100篇-python刷题记录】【旋转图像】

R7-矩阵篇

印象题:

思路:

先转置,转置完我们按照列的中间进行对称交换就可以了。

python 复制代码
class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        n=len(matrix)
        matrix[:]=[list(row) for row in zip(*matrix)]
        for j in range(n//2):
            for i in range(n):
                matrix[i][j],matrix[i][n-j-1]=matrix[i][n-j-1],matrix[i][j]

ps:

注意matrix重新矩阵赋值的时候,需要

python 复制代码
matrix[:]
相关推荐
天诰33 分钟前
SA-K-11 检索会消失吗与四个未解问题
java·服务器·人工智能·python·机器学习·ai编程
benchmark_cc1 小时前
用 QuantDash 读取美股行情:AAPL.US 的运行前检查、排错顺序与数据校验清单
python·数据分析·pandas·量化交易·股票数据·quantdash
蜗牛一步步往上爬3 小时前
第十六章 C++语言在深度学习中的应用
开发语言·c++·深度学习
羲云网络5 小时前
GPT Image 2.6 接入指南:Flare、Sunburst 怎么选,编辑失败如何排查
人工智能·python·aigc·图像生成·acedatacloud
张张123y5 小时前
DSH 插件调试避坑:client.js 设置面板、热重载与高频报错排查表
开发语言·javascript·人工智能·开源·ecmascript·后端开发·ai agent
likexuec5 小时前
数据结构(2)
数据结构
Navigator_Z6 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
D e re k ZH7 小时前
C++ 标准库算法全景指南
数据结构·c++·算法
冻柠檬飞冰走茶8 小时前
字母移动游戏题解:贪心求最长可保留连续子串(附 C 实现)
c语言·开发语言·数据结构·算法·动态规划