I am trying to solve the Pascal's triangle problem in python3 but keep getting TypeError 'int' object is not subscriptable everytime.
Here, the question is: Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
pascal = []
for i in range(numRows):
pascal.append([])
for j in range(i+1):
if j == 0 or j == i:
pascal.append(1)
else:
pascal[i].append(pascal[i - 1][j - 1] + pascal[i - 1][j])
return pascal