题目:
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] ]
class Solution(object):
def sumunms(self,nums):
sans = [1]
for i in range(1,len(nums)):
sans.append(nums[i]+nums[i-1])
sans.append(1)
return sans
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if numRows==0:
return []
if numRows==1:
return [[1]]
if numRows==2:
return [[1],[1,1]]
results = [[1],[1,1]]
ans = [1,1]
while numRows>2:
ans = self.sumunms(ans)
results.append(ans)
numRows-=1
return results
a = Solution()
print a.generate(5)