题解 | #杨辉三角(一)# | Rust
杨辉三角(一)
https://www.nowcoder.com/practice/4385fa1c390e49f69fcf77ecffee7164
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型 * @return int整型二维数组 */ pub fn generate(&self, num: i32) -> Vec<Vec<i32>> { let mut ans:Vec<Vec<i32>> = Vec::with_capacity(num as usize); for i in 0..num as usize { let mut item:Vec<i32> = vec![1; i+1]; for j in 1..i { item[j] = ans[i-1][j] + ans[i-1][j-1]; } ans.push(item); } return ans; } }