本地跑没问题,在页面上出错,写的应该是对的
import numpy as np
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: None Do not return anything, modify matrix in-place instead.
"""
L =len(matrix)
matrix = np.array(matrix)
for i in range(int(L / 2)):
for j in range(L - 1 - 2 * i):
a = matrix[i][L-i-1]
b = matrix[L-i-1][L-i-1]
c = matrix[L-i-1][i]
d = matrix[i][i]
matrix[i, i + 1:L - i], matrix[i + 1:L - i, L - i-1], matrix[L - i-1, i:L - i - 1], matrix[i:L - i-1, i] = \
matrix[i, i:L - 1 - i], np.append(a, matrix[i+1:L - 1 - i, L - i-1]), np.append(matrix[L - i-1, i + 1:L - i-1], b), np.append(matrix[i + 1:L - i-1, i], c)