Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.  For example, given numRows = 5

It's easy to solve.

class Solution:
    # @return a list of lists of integers
    def generate(self, numRows):
        if numRows<=0:
            return []
        elif numRows==1:
            return [[1]]
            
        result = [[1]]
        for rowInd in range(1,numRows):
            newrow = [1]
            for ind in range(1,rowInd):
                newrow = newrow + [ result[rowInd-1][ind-1]+result[rowInd-1][ind]  ]
            newrow = newrow + [1]
            
            result.append(newrow)
        
        return result


你可能感兴趣的:(LeetCode)