https://leetcode-cn.com/problems/pascals-triangle/description/
https://leetcode-cn.com/problems/pascals-triangle-ii/description/
两题基本是一样的,一开始用numpy,用数组处理,好像不能import numpy,playground不报错,执行界面报错。后来学了网上大牛的,把list当二维数组用,看得有点懵。。。。
贴个118的代码吧,119的改一下返回值就可以。
class Solution(object): def generate(self, numRows): L = [] if numRows == 0: return L for i in range(numRows): L.append([1]) for j in range(1,i+1): if j==i: L[i].append(1) else: L[i].append(L[i-1][j]+L[i-1][j-1]) return L