[
dp
math
]
BinarySearch 0124 Pascal's Triangle
Problem statement
https://binarysearch.com/problems/Pascal's-Triangle/
Solution
Equal to Leetcode 0119. Pascal’s Triangle II.
Complexity
It is O(k^2)
for time and O(k)
for space.
Code
class Solution:
def solve(self, rowIndex):
return reduce(lambda r,_:[1]+[r[j]+r[j+1] for j in range(len(r)-1)]+[1], range(rowIndex),[1])