#-*- 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)
相关文章
- 12-21[leetcode]Pascal's Triangle @ Python
- 12-21Leetcode_119_Pascal's Triangle II
- 12-21【LeetCode】120. Triangle 解题报告(Python)
- 12-21LeetCode & Q119-Pascal's Triangle II-Easy
- 12-2128. Triangle && Pascal's Triangle && Pascal's Triangle II
- 12-21Leetcode练习(Python):哈希表类:第76题:最小覆盖子串:给你一个字符串 S、一个字符串 T,请在字符串 S 里面找出:包含 T 所有字母的最小子串。
- 12-21【leetcode】Pascal's Triangle
- 12-21【Leetcode】Pascal's Triangle II
- 12-21【leetcode】Pascal's Triangle I & II (middle)
- 12-21[LeetCode]题解(python):120 Triangle