题解 | 顺时针打印矩阵

顺时针打印矩阵

https://www.nowcoder.com/practice/9b4c81a02cd34f76be2659fa0d54342a

# -*- coding:utf-8 -*-
class Solution:
    # matrix类型为二维列表,需要返回列表
    def printMatrix(self, matrix):
        # write code here
        ans = []#存储返回输出结果的列表
        while matrix:#对矩阵进行逆时针截取操作
            ans += matrix[0]
            matrix = list(zip(*matrix[1:]))[::-1]
        return ans

全部评论

相关推荐

10-17 17:54
门头沟学院 Java
点赞 评论 收藏
分享
11-04 10:30
已编辑
门头沟学院 研发工程师
开心小狗🐶:“直接说答案”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务