""" 0119.1 - Solution 1 - Build Row Iteratively """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def getRow(self, rowIndex: int) -> List[int]:
"""Return the rowIndex-th row of Pascal's Triangle"""
triangle = [[1]]
for i in range(1, rowIndex + 1):
row = [1]
for j in range(1, i):
row.append(triangle[i - 1][j - 1] + triangle[i - 1][j])
row.append(1)
triangle.append(row)
return triangle[rowIndex]
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().getRow(3)) # [1, 3, 3, 1]
print(Solution().getRow(0)) # [1]
print(Solution().getRow(1)) # [1, 1]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0119.2 - Solution 2 - In-Place Single Row (O(k) Space) """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def getRow(self, rowIndex: int) -> List[int]:
"""Return the rowIndex-th row of Pascal's Triangle using O(k) space"""
row = [1] * (rowIndex + 1)
for i in range(2, rowIndex + 1):
for j in range(i - 1, 0, -1):
row[j] += row[j - 1]
return row
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().getRow(3)) # [1, 3, 3, 1]
print(Solution().getRow(0)) # [1]
print(Solution().getRow(1)) # [1, 1]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()