【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[:]
相关推荐
前端付豪44 分钟前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽1 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋7 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
Wect8 小时前
LeetCode 130. 被围绕的区域:两种解法详解(BFS/DFS)
前端·算法·typescript
NAGNIP20 小时前
一文搞懂深度学习中的通用逼近定理!
人工智能·算法·面试
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python