import numpy as npclassSolution:defgenerateMatrix(self,n:int) -> List[List[int]]:defgenerateMatrix(start,matrix): end = start +len(matrix[0]) matrix[0]= [i for i inrange(start, end)]iflen(matrix)!=1: matrix[1:]= np.transpose(np.flip(generateMatrix(end, np.transpose(np.flip(matrix[1:], 0))), 0))return matrixreturngenerateMatrix(1, [[0for i inrange(n)] for j inrange(n)])
classSolution: defgenerateMatrix(self,n:int) -> List[List[int]]:defgenerateMatrix(start,matrix): return [[i for i inrange(start, start +len(matrix[0]))]] + [list(i)for i in [*zip(*generateMatrix(start +len(matrix[0]), [*zip(*matrix[1:][::-1])])[::-1])]] iflen(matrix)>1else [[i for i inrange(start, start +len(matrix[0]))]]returngenerateMatrix(1, [[0for i inrange(n)] for j inrange(n)])