A concise Python solution using list comprehension


  • 0
    F
        def generate(self, numRows):
            """
            :type numRows: int
            :rtype: List[List[int]]
            """
            template, res = [1], []
            for _ in range(numRows):
                res.append(t)
                template = [x+y for x,y in zip([0]+template, template + [0])]
            return res
    

Log in to reply
 

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