Sunday, September 7, 2014

Leetcode: Pascal's Triangle @Python

class Solution:
    # @return a list of lists of integers
    def generate(self, numRows):
        if numRows==0:
            return[]
        rst=[[1]]
        i=1
        for j in range(1,numRows):
            row=[1]
            for i in range(1,j):
                row+=[rst[-1][i-1]+rst[-1][i]]
            row+=[1]
            rst.append(row)
        return rst

No comments :

Post a Comment