【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[:]
相关推荐
Want5951 分钟前
Python跳动的爱心②
开发语言·python·数学建模
田里的水稻4 分钟前
PyTorch_TensorBoard展示
人工智能·pytorch·python·深度学习·神经网络
张张123y24 分钟前
后端第九课:部署上线(把你的 FastAPI 后端真正跑起来给别人用)
python·docker·部署·fastapi
云勤通30 分钟前
智慧后勤系统哪家定制能力强
大数据·python
Navigator_Z35 分钟前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
想七想八不如114081 小时前
元学习简单入门
人工智能·pytorch·python·深度学习·学习·机器学习
小羊没烦恼!1 小时前
T-SQL查询进阶--理解SQL SERVER中的分区表
服务器·开发语言·前端·javascript·html
Zucker n1 小时前
一款适合研究生科研工作安排的日历
linux·数据库·python
Nil2081 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
光影少年1 小时前
AI Agent、自动化与未来工作
人工智能·算法·架构