leetcode简单题27 N.119 杨辉三角II rust描述

avatar
作者
猴君
阅读量:2


 

// 直接生成杨辉三角当前行 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] + row[j - 1];         }     }      row } // 空间优化的方法 pub fn get_row2(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] + row[j - 1];         }     }      row } // 数学组合数公式 pub fn get_row3(row_index: i32) -> Vec<i32> {     let mut row = vec![1; (row_index + 1) as usize];      for k in 1..=row_index as usize {         row[k] = (row[k - 1] as u64 * (row_index - k as i32 + 1) as u64 / k as u64) as i32;     }      row } fn main() {} 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!