这题顺着Pascal's Triangle I的思路来很快,去掉1的输出结果,直接提取中间的结果就可以了。代码如下:
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
if rowIndex <= 0:
return [1]
if rowIndex == 1:
return [1, 1]
listoffirst = [1, 1]
listofmiddle = []
while rowIndex - 1 > 0:
for i in range(len(listoffirst) - 1):
listofmiddle.append(listoffirst[i] + listoffirst[i + 1])
listofmiddle.append(1)
listofmiddle.insert(0, 1)
listoffirst = listofmiddle
listofmiddle = []
rowIndex = rowIndex - 1
return listoffirst