118. 杨辉三角
This commit is contained in:
parent
fb53c164a8
commit
a44111df84
22
src/main.rs
22
src/main.rs
|
@ -1,19 +1,21 @@
|
||||||
use std::cmp::max;
|
|
||||||
|
|
||||||
struct Solution;
|
struct Solution;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
|
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
|
||||||
let mut a = 0;
|
let mut ans : Vec<Vec<i32>>= vec![vec![1]];
|
||||||
let mut b = 1;
|
for i in 1..num_rows {
|
||||||
for i in derived.iter() {
|
let mut row = vec![1];
|
||||||
a ^= i;
|
let prev_row = &ans[(i - 1) as usize];
|
||||||
b ^= i;
|
for j in 1..prev_row.len() {
|
||||||
|
row.push(prev_row[j - 1] + prev_row[j]);
|
||||||
|
}
|
||||||
|
row.push(1);
|
||||||
|
ans.push(row);
|
||||||
}
|
}
|
||||||
a == 0 || b == 1
|
ans
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sl = Solution::does_valid_array_exist(vec![1,1,0]);
|
let sl = Solution::generate(7);
|
||||||
println!("{:?}", sl);
|
println!("{:?}", sl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue