class Solution:
def getNSample(self, n) -> List[int]:
result = []
sample = 1
for i in range(1, n + 1):
sample *= i
result.append(sample)
return result
def getRow(self, rowIndex: int) -> List[int]:
if rowIndex == 0:
return [1]
rowIndex += 1
result = []
nSample = self.getNSample(rowIndex - 1)
result.append(1)
for i in range(1, rowIndex - 1):
result.append(int(nSample[-1] / (nSample[i - 1] * nSample[rowIndex - i - 2])))
result.append(1)
return result
這個版本不錯,速度飛快,主要是用了組合公式