119. Pascal's Triangle II

119. Pascal's Triangle II

[Easy] “Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal’s triangle."

Link to Leetcode

Python3:

class Solution:
    def getRow(self, rowIndex: int) -> List[int]:
        last = []
        res = []
        for i in range(0, rowIndex + 1):
            if i == 0:
                last = [1]
                res = [1]
            else:
                last = res
                row_inner = [(last[j - 1] + last[j]) for j in range(1, len(last))]
                res = [1] + row_inner + [1]

        return res