Loading RustViz Engine...
Generate the first num_rows of Pascal triangle allocating exact capacities.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn generate_pascals_triangle(num_rows: usize) -> Vec<Vec<u32>> {
let mut triangle = Vec::with_capacity(num_rows);
for i in 0..num_rows {
let mut row = vec![1; i + 1];
for j in 1..i {
row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
}
triangle.push(row);
}
triangle
}