先将矩阵转置,然后再翻转每一行
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
n = len(matrix[0])
for i in range(n):
for j in range(i,n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for k in range(n):
matrix[k].reverse()
对于矩阵操作首先要思考矩阵的各种性质