Skip to main content
Back to problems
#119
Easy Algorithms

Pascals triangle ii

Array Dynamic Programming
67.1% acceptance
Jan 12, 2026
5286
369
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

Solution

Rust
Time O(n²)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn get_row(row_index: i32) -> Vec<i32> {
    let mut row = vec![1; (row_index + 1) as usize];
    
    for i in 1..=row_index as usize {
      for j in (1..i).rev() {
        row[j] += row[j - 1];
      }
    }
    
    row
  }
}