easy to understand Python solution

  • 0
    class Solution(object):
        def findDiagonalOrder(self, matrix):
            M = len(matrix)
            if M==0: return []
            N = len(matrix[0])
            r = []
            for k in xrange(M+N+1):
                upper = min(M, k+1)
                lower = max(0, k-N+1)
                s = [matrix[i][k-i] for i in xrange(lower, upper)]
                if k % 2 == 0: s = reversed(s)
            return r

Log in to reply

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