You are given an integer numRows, return the first numRows of Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

Example 1:
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]Example 2:
Input: numRows = 1
Output: [[1]]Constraints:
1 <= numRows <= 30Before attempting this problem, you should be comfortable with:
Each element in Pascal's Triangle corresponds to a binomial coefficient. The value at row n and position k is C(n, k). Rather than computing each coefficient from scratch using factorials, we can compute them incrementally. Starting from 1, each subsequent value in a row can be derived by multiplying by (n - k + 1) / k.
n from 0 to numRows - 1:[1].val = 1.k from 1 to n:val = val * (n - k + 1) / k.val to the row.row to the result.Each element in Pascal's Triangle (except the edges) is the sum of the two elements directly above it. We can simulate this by padding the previous row with zeros on both ends, then summing adjacent pairs to generate the next row.
[[1]].[0] + row + [0].temp[j] + temp[j + 1].row to the result.numRows rows.We directly apply the defining property of Pascal's Triangle: each interior element equals the sum of the two elements above it. The first and last elements of every row are always 1. We build row by row, referencing the previous row for the sums.
i has i + 1 elements, all set to 1.j (not the first or last):res[i][j] = res[i - 1][j - 1] + res[i - 1][j].Pascal's Triangle is often 0-indexed, so row 0 is [1], row 1 is [1, 1], and so on. Confusing 0-indexed and 1-indexed row numbering leads to generating one too many or one too few rows. Always clarify whether numRows means the count of rows or the index of the last row.
The first and last elements of every row are always 1. When building rows iteratively, only the interior elements (positions 1 through i-1 for row i) need to be computed as sums. Attempting to compute edge elements using the sum formula causes index-out-of-bounds errors.