Problem
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal’s triangle.
In Pascal’s triangle, each number is the sum of the two numbers directly above it
Algorithm
Dynamic Programming (DP). F(i, j) = F(i-1, j-1) + F(i-1, j).
Code
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
ans = [1]
for i in range(1, rowIndex+1):
buf = [1]
for j in range(1, i):
buf.append(ans[j-1] + ans[j])
buf.append(1)
ans = buf.copy()
return ans