首先水平中轴翻转
然后再沿正对角线翻转
class Solution: def rotateMatrix(self, mat, n): # write code here # for i in range(n//2): mat[i], mat[n-i - 1] = mat[n-i - 1], mat[i] for i in range(n): for j in range(i): mat[i][j], mat[j][i] = mat[j][i], mat[i][j] return mat
首先水平中轴翻转
然后再沿正对角线翻转
class Solution: def rotateMatrix(self, mat, n): # write code here # for i in range(n//2): mat[i], mat[n-i - 1] = mat[n-i - 1], mat[i] for i in range(n): for j in range(i): mat[i][j], mat[j][i] = mat[j][i], mat[i][j] return mat