triangle
1
Brute force · binomial formula
▸1for r ← 0 to rows − 1:2 for c ← 0 to r: entry ← r! / (c! · (r − c)!)3# factorials overflow quickly and repeat work
state
- rows5
warming up the animation
Given numRows, return the first numRows of Pascal's triangle. Each number is the sum of the two directly above it.
▸1for r ← 0 to rows − 1:2 for c ← 0 to r: entry ← r! / (c! · (r − c)!)3# factorials overflow quickly and repeat work
line 1Each entry has a closed form: row r, column c is C(r, c) = r! / (c! · (r − c)!). Compute every one independently.