地址:点击打开链接
这个三角的变形版本,下标有点变化
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
return self.generate(rowIndex+1)[-1]
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if numRows == 0:
return [[]]
if numRows <= 2:
return [ [1]*i for i in range(numRows+1) if i > 0]
ret = []
for i in range(1,numRows+1):
if i < 3:
curRaws = [1] * i
ret.append(curRaws)
else:
curRaws = [1] * i
for i in range(1,len(curRaws)-1):
curRaws[i] = ret[-1][i] + ret[-1][i-1]
ret.append(curRaws)
return ret