面试150 旋转图像

面试150 旋转图像_第1张图片

思路

解包法。zip函数可以使矩阵转置,本题需要对矩阵先反转在转置。因此联想到zip是一种很简便的方法

class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        matrix[:]=zip(* matrix[::-1])

你可能感兴趣的:(面试150题目,面试,leetcode,数组)