#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param mat int整型二维数组
# @param n int整型
# @return int整型二维数组
#
class Solution:
def rotateMatrix(self , mat: List[List[int]], n: int) -> List[List[int]]:
# write code here
'''
res = [[ 0 for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
res[i][j] = mat[n-j-1][i]
return res
'''
for i in range(n):
for j in range(i):
mat[i][j], mat[j][i] = mat[j][i], mat[i][j] # 矩阵转置
for i in range(n):
for j in range(n//2):
mat[i][j], mat[i][n-j-1] = mat[i][n-j-1], mat[i][j] #每一行做中心翻转
return mat