思路
观察列表,旋转后:
第N行的数据=原列表第N列数据从下往上遍历
则用re来存储原列表每列从下往上遍历的数据,然后赋值给matrix即可
时间复杂度: O(n^2)
代码
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
re=[]
for j in range(len(matrix[0])):
t=[]
for i in range(len(matrix)-1,-1,-1):
t.append(matrix[i][j])
re.append(t)
for i in range(len(matrix)):
for j in range(len(matrix[0])):
matrix[i][j]=re[i][j]
return matrix
标签:matrix,48,len,旋转,re,range,图像,列表,append
From: https://blog.csdn.net/huanxianxianshi/article/details/144516017