【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[:]
相关推荐
@卞5 分钟前
高阶数据结构 --- 单调队列
数据结构·c++·算法
星光一影18 分钟前
基于PHP+MySQL+Uniapp的上门家政服务系统源码
开发语言·mysql·uni-app·php
Antonio91520 分钟前
【Swift】 UIKit:UIGestureRecognizer和UIView Animation
开发语言·ios·swift
D***t13124 分钟前
PHP在API开发中的框架选择
开发语言·php
H***997624 分钟前
Java虚拟现实案例
java·开发语言·vr
7***n7525 分钟前
Python虚拟现实案例
python·vr·pygame
Tan_Ying_Y36 分钟前
synchronized和ReentrantLock的区别是什么?他们的底层原理是什么?
开发语言·c#
ChineHe43 分钟前
Golang并发编程篇002_Go并发基础
开发语言·后端·golang
默恋~微凉43 分钟前
shell(八)——WEB与Nginx
开发语言·前端·php
程序员爱钓鱼1 小时前
Python编程实战:Python常用命令速查表(超全整理)
后端·python·trae