From 19dc215202160819a7a9a776a7654e44e804192c Mon Sep 17 00:00:00 2001 From: Sejal Jagtap Date: Tue, 11 Nov 2025 13:25:33 -0600 Subject: [PATCH] pascal-triangle.py --- pascal-triangle.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pascal-triangle.py diff --git a/pascal-triangle.py b/pascal-triangle.py new file mode 100644 index 00000000..6aff1d9b --- /dev/null +++ b/pascal-triangle.py @@ -0,0 +1,25 @@ +class Solution: + def generate(self, numRows: int) -> List[List[int]]: + '''1 + 1 1 + 1, 2, 1 + 1, 3, 3, 1 + 1, 4, 6, 4, 1 + 1, 5, 10, 10, 5, 1 + + 1, ...sum of each 2 .., 1''' + + first_two = {1: [[1]], 2:[[1], [1, 1]]} + + if numRows < 3: + return first_two[numRows] + + result = [[1], [1, 1]] + for i in range(2, numRows): + temp = [1] + for j in range(len(result[i-1])-1): + temp.append(result[i-1][j] + result[i-1][j+1]) + temp.append(1) + result.append(temp) + return result +