极简python代码

顺时针打印矩阵

http://www.nowcoder.com/questionTerminal/9b4c81a02cd34f76be2659fa0d54342a

python大法:
每次只取第一行数据,然后再把矩阵逆时针旋转90度

    class Solution:
        # matrix类型为二维列表,需要返回列表
        def printMatrix(self, matrix):
            # write code here
            res = []
            while matrix:
                res += matrix.pop(0)
                matrix = list(zip(*matrix))[::-1]
            return res
全部评论
您好 matrix.pop(0)是一个元组 为什么res += 可以正确 但是 res = res + 就不行?
点赞 回复 分享
发布于 2021-05-19 11:06

相关推荐

评论
20
2
分享

创作者周榜

更多
牛客网
牛客企业服务