119. Pascal's Triangle II
https://leetcode.com/problems/pascals-triangle-ii
Python
Recursive
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
if rowIndex == 0:
return [1]
if rowIndex == 1:
return [1, 1]
return self._generate(2, rowIndex, [1, 1])
def _generate(self, level, target_level, pre_level):
if level > target_level:
return pre_level
current = [1]
for i in range(1, len(pre_level)):
pre = pre_level[i-1]
cur = pre_level[i]
current.append(pre+cur)
current.append(1)
return self._generate(level+1, target_level, current)