【leetcode❤python】118. Pascal's Triangle
#-*- coding: UTF-8 -*-
#杨辉三角
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
result=[];row=1
while True:
tmplist=[1]*row
i=0;flag=0
while True:
if i==0:
tmplist[0]=1;tmplist[row-1]=1
flag+=2
else:
tmplist[i]=result[row-2][i-1]+result[row-2][i]
tmplist[row-i-1]=tmplist[i]
flag+=2
i+=1
if flag>=row:break
result.append(tmplist)
row+=1
if row>numRows:break
return result
sol=Solution()
print sol.generate(1)