mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
16 lines
512 B
Python
16 lines
512 B
Python
class Solution:
|
|
def getRow(self, rowIndex: int) -> List[int]:
|
|
def combination(n: int, r: int) -> int:
|
|
# n! / (n - r)!
|
|
numerator = 1
|
|
for i in range(n - r + 1, n + 1):
|
|
numerator *= i
|
|
|
|
# 1 / r!
|
|
divisor = 1
|
|
for j in range(2, r + 1):
|
|
divisor *= j
|
|
|
|
return int(numerator / divisor)
|
|
|
|
return [ combination(rowIndex, i) for i in range(rowIndex + 1) ] |