Skip to main content
Back to problems
Leetcode
Medium
Arrays
Combinatorics
Math
Pascal's Triangle

Generate the first numRowsnumRows rows of Pascal's triangle, where each number is the sum of the two numbers directly above it.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

Given an integer numRows, return the first numRows rows of Pascal's Triangle.

Pascal's Triangle is built row by row:

  • The first row is [1].
  • Each subsequent row starts and ends with 1.
  • Every inner value is the sum of the two values directly above it from the previous row.

Your task is to construct and return the triangle up to the requested number of rows.

Notes

  • Row indexing is 1-based in the natural description of the triangle.
  • You only need to return the rows that exist; do not pad shorter rows.

Input Format

  • A single integer numRows.
  • numRows is the number of rows to generate.

Output Format

  • Return a list of lists of integers representing the first numRows rows of Pascal's Triangle.

Constraints

  • 1numRows301 \le numRows \le 30
  • All generated values fit in a 32-bit signed integer.
Examples
Sample cases returned by the problem API.

Example 1

Input

numRows = 5

Output

[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]

Explanation

Start with [1]. Each new row is formed by adding adjacent pairs from the previous row, with 1 at both ends.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.