您的位置:首页 > 其它

[leetcode]#119. Pascal's Triangle II

2017-11-27 20:22 399 查看
跟上一题一样,只是返回的值是指定的某一行

For example, given k = 3,

Return [1,3,3,1].

class Solution:
# @return a list of integers
def getRow(self, rowIndex):
rownum=rowIndex+1
currow=[1]
if rownum==1:
return currow
if rownum>0:
currow=[1]
for index in range(rownum):
prerow=currow
currow=[1]
for j in range(index-1):
currow.append(prerow[j]+prerow[j+1])
currow.append(1)
return currow
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode