|
NameError: name 'List' is not defined 的意思是 List这个变量你没有进行定义。Python的标准库中没有List,只有list这个内建函数。
这么写,就可以了。
class Solution:
def power(self, matrix):
if not matrix : return []
res = []
while matrix:
res.extend(matrix.pop(0))
next_matrix = []
for x in zip(*matrix):
next_matrix.append(x)
matrix = next_matrix[::-1]
return res
matrix = [[1,2,3],[4,5,6],[7,8,9]]
Solution().power(matrix)
print(Solution().power(matrix))
建议去下载一个Pycharm工具,进行Python代码的编辑,PyCharm会将明显的语法错误表示出来 |
|