题解 | #顺时针打印矩阵#
顺时针打印矩阵
https://www.nowcoder.com/practice/9b4c81a02cd34f76be2659fa0d54342a
参考题解区思路,逆转矩阵。
中间过程(res,matrix)的输出方便理解。
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param matrix int整型二维数组
# @return int整型一维数组
#
class Solution:
def printMatrix(self , matrix: List[List[int]]) -> List[int]:
res=[]
while matrix!=[]:
res += matrix.pop(0) #取出第一行。就地加法+=可以把list和元组相加
#res=res+matrix.pop(0) #can only concatenate list (not "tuple") to list
matrix=list(zip(*matrix))[::-1]#旋转90度
return res zip函数


海康威视公司福利 1160人发布