One more simple solution


  • 0
    E

    Idea of my solution is:

    1. move first row of matrix in answer
    2. delete it from original matrix
    3. rotate -90* rest of matrix
    4. repeat 1-3 steps until initial matrix become empty
    class Solution(object):
        
        def spiralOrder(self, matrix):
            """
            :type matrix: List[List[int]]
            :rtype: List[int]
            """
    
            answer=[]
                     
            while len(matrix)>0:
                answer.extend(matrix[0])
                del matrix[0]
                matrix = zip(*matrix)
                matrix = matrix[::-1]
    
            return(answer)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.