118.Pascal's Triangle

 

 

 

 

class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        if numRows == 0:
            return None
        if numRows == 1:
            return [[1]]
        ans = [[1]]
        for j in range(1,numRows):
            tmp = [1 for i in range(j+1)]
            for i in range(1, j):
                tmp[i] = ans[j-1][i-1] + ans[j-1][i]
            ans.append(tmp)
        return ans

 

posted @ 2020-05-09 15:03  星海寻梦233  阅读(100)  评论(0编辑  收藏  举报