Short python answer, 7-lines


  • 3
    H
    class Solution(object):
    def generate(self, numRows):
        """
        :type numRows: int
        :rtype: List[List[int]]
        """
        if numRows <= 0:
            return []
        triangle = [[1]]
        for i in range(1, numRows):
            row = [0] + triangle[-1] + [0]
            triangle.append([row[j]+row[j+1] for j in range(i+1)])
        return triangle

  • 0
    J

    beautiful code!


Log in to reply
 

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