Question Link:
https://leetcode.com/problems/pascals-triangle/
没啥可说的,直接上code吧……
[-]
Python code accepted by LeetCode OJ
class Solution:
# @return a list of lists of integers
def generate(self, numRows):
# Initialize the triangle
res = []
for i in xrange(numRows):
res.append([1] * (i+1))
# Compute the triangle row by row
for row in xrange(1, numRows):
for i in xrange(1, row):
res[row][i] = res[row-1][i] + res[row-1][i-1]
# Return
return res