diff --git a/solution/0100-0199/0118.Pascal's Triangle/Solution.py b/solution/0100-0199/0118.Pascal's Triangle/Solution.py new file mode 100644 index 0000000000000..5855e99025197 --- /dev/null +++ b/solution/0100-0199/0118.Pascal's Triangle/Solution.py @@ -0,0 +1,18 @@ +class Solution: + def generate(self, numRows: int) -> List[List[int]]: + res = [[1], [1, 1]] + if numRows == 0: + return [] + elif numRows == 1: + return [res[0]] + + # from the 3. row on + for i in range(2, numRows): + counter = 1 + temp = [1, 1] + # should add len(res[i - 1]) - 1 elements in to temp + for j in range(len(res[i - 1]) - 1): + temp.insert(counter, res[i - 1][j] + res[i - 1][j + 1]) + counter += 1 + res.append(temp) + return res