class Solution:
# time O(N)  space O(N)
    def getRow(self, rowIndex: int) -> List[int]:
        pre = []
        for i in range(rowIndex+1):  # i: row 
            cur = []
            j = 0 # j: col 
            while  j <= i :
                if j == 0 or j == i:
                    cur.append(1)
                else:
                    cur.append(pre[j-1]+pre[j])
                j += 1
            pre  = cur
        return cur 

class Solution:
    # time O(N) space O(K)
    def getRow(self, roswIndex: int) -> List[int]:
        cur = [1] # res for each row 
        pre = 1
        for i in range(1,rowIndex+1):# from row 2
            j = 1
            while j < i:
                temp = cur[j]
                cur[j] = pre + cur[j]
                pre = temp # pre save the value of last row at the same position 
                j += 1 
            cur.append(1)
        return cur