[leetcode]#118. Pascal's Triangle

来源:互联网 发布:淘宝女鞋推荐 编辑:程序博客网 时间:2024/06/05 08:12

题意:每一层的第i个位置,等于上一层第i-1与第i个位置之和。

[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]

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