[1, 2, 4, 3] is not a wrong answer


  • 0
    C
    class Solution:
    def _spiral_order(self, sx, sy, ex, ey, matrix, res):
        x = ex - sx + 1
        y = ey - sy + 1
        if x <= 0 or y <= 0:
            return
    
        res.extend(matrix[sy][sx:(ex+1)])
        if y > 1:
            for i in range(sy+1, ey):
                res.append(matrix[i][ex])
            res.extend(reversed(matrix[ey][sx:(ex+1)]))
            if x > 1:
                for i in range(ey-1, sy, -1):
                    res.append(matrix[i][sx])
                print res
                self._spiral_order(sx+1, sy+1, ex-1, ey-1, matrix, res)
    
        return
    
    # @param matrix, a list of lists of integers
    # @return a list of integers
    def spiralOrder(self, matrix):
        res = []
        n = len(matrix)
        if n == 0:
            return res
        m = len(matrix[0])
    
        self._spiral_order(0, 0, m - 1, n - 1, matrix, res)
        return res
    

    I got "Wrong answer" but looks like I'm right, there are some space between elements in Python list.
    Submission Result: Wrong Answer

    Input: [[1,2],[3,4]]

    Output: [1, 2, 4, 3]

    Expected: [1,2,4,3]


Log in to reply
 

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