题解 | #螺旋矩阵#

螺旋矩阵

https://www.nowcoder.com/practice/7edf70f2d29c4b599693dc3aaeea1d31?tpId=295&tqId=693&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param matrix int整型二维数组 
# @return int整型一维数组
#
class Solution:
    def spiralOrder(self , matrix: List[List[int]]) -> List[int]:
        # write code here
        L=[]
        while matrix:
            for i in range(len(matrix[0])):
                L.append(matrix[0][i])
        
            matrix.remove(matrix[0])
		  #用python将矩阵逆时针翻转过来
            matrix = list(map(list,zip(*matrix)))[::-1]
        return L

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务