【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[:]
相关推荐
databook7 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室7 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三9 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271112 小时前
Python之语言特点
python
刘立军12 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
聚客AI14 小时前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
数据智能老司机16 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
大怪v16 小时前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
数据智能老司机17 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i18 小时前
django中的FBV 和 CBV
python·django