Problem
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.
In Pascal’s triangle, each number is the sum of the two numbers directly above it.
Example:
1 |
|
Explanation
-
After observing the triangle. We find out that each row, the first column value and the last column value is always 1, and the number of column is equal to the number of row.
-
In each row, we have the formula to calculate the current number’s value: $currVal = prevVal * (currRow - prevCol) / prevCol$ (Row index and column index start from 1).
Solution
1 |
|