fn main() { println!("Hello, world!"); let tests = vec![ (5, vec![ vec![1],vec![1,1],vec![1,2,1],vec![1,3,3,1],vec![1,4,6,4,1] ]), (1, vec![vec![1]]) ]; for test in tests { println!("{} is {:?} should be {:?}", test.0, Solution::generate(test.0), test.1); } } struct Solution {} impl Solution { pub fn generate(num_rows: i32) -> Vec> { let mut rows = Vec::with_capacity(num_rows as usize); rows.push(vec![1]); for i in 1..num_rows { let mut row: Vec = Vec::with_capacity((i+1) as usize); for ii in 0..=i { let above = &rows[(i-1) as usize]; row.push(if ii == 0 || i == ii {1} else {above[(ii-1) as usize] + above[ii as usize]}); } rows.push(row); } rows } }