#118. Pascal's Triangle
2017-03-25 本文已影响17人
Double_E
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,Return
[ [1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]]
Subscribe to see which companies asked this question
Python
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
x = []
for i in range(numRows):
t = [1] * (i + 1)
x.append(t)
for j in range(1, i):
x[i][j] = x[i-1][j-1] + x[i-1][j]
return x