解题思路
本题思路就是,先将二维数组左右对调,再沿着反对角线对调。
代码
class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ N = len(matrix) #列数==列数 for i in range(N): for j in range(N//2): a = matrix[i][N-1-j] matrix[i][N-1-j] = matrix[i][j] matrix[i][j] = a for i in range(N): for j in range(N-i-1): a = matrix[N-j-1][N-i-1] matrix[N-j-1][N-i-1] = matrix[i][j] matrix[i][j] = a return matrix