https://leetcode-cn.com/problems/pascals-triangle-ii/
class Solution:
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
res = [0] * (rowIndex+1)
num, j = 1, 1
res[0] = 1
if rowIndex == 0:
return res
#用组合数C(rowIndex,k),k从1到rowIndex的一半,剩下一半对称
mid = rowIndex // 2
for i in range(1, mid+1):
num *= (rowIndex + 1 - i)
num //= j
j += 1
res[i] = num
if rowIndex % 2 == 0:
res[mid+1:] = res[mid-1::-1]
else:
res[mid+1:] = res[mid::-1]
return res