#119. Pascal's Triangle II
2017-03-25 本文已影响6人
Double_E
Python
for example
let L=rowIndex + 1
1, 1, 1, 1
So L=4, let i = range(1, L) and j=range(1, i)
i = 1, j = range(1, 1) 不运行
i = 2, j = 1
1, 2, 1, 1
i = 3, j = 1
1, 2, 3, 1 ... 1 = 1 + 2
i = 3, j = 2
1, 3, 3, 1 ... 2 = 1+2
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
L = rowIndex + 1
x = [1] * L
for i in range(1, L):
for j in range(1, i):
x[i - j] += x[i - j - 1]
return x