20250128 finished.
This commit is contained in:
parent
70883c231b
commit
4358c2555c
|
@ -1,10 +1,10 @@
|
||||||
use crate::fetch_problem::{Fetcher, ProblemManager};
|
use crate::fetch_problem::{Fetcher, ProblemManager};
|
||||||
|
use anyhow::anyhow;
|
||||||
|
use serde::de::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::exists;
|
use std::fs::exists;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use anyhow::anyhow;
|
|
||||||
use serde::de::Error;
|
|
||||||
|
|
||||||
mod fetch_problem;
|
mod fetch_problem;
|
||||||
|
|
||||||
|
|
|
@ -456,3 +456,5 @@ mod p2944_minimum_number_of_coins_for_fruits;
|
||||||
mod p2412_minimum_money_required_before_transactions;
|
mod p2412_minimum_money_required_before_transactions;
|
||||||
|
|
||||||
mod p40_combination_sum_ii;
|
mod p40_combination_sum_ii;
|
||||||
|
|
||||||
|
mod p119_pascals_triangle_ii;
|
||||||
|
|
43
src/problem/p119_pascals_triangle_ii.rs
Normal file
43
src/problem/p119_pascals_triangle_ii.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* [119] Pascal's Triangle II
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
//0 1
|
||||||
|
//1 1 1
|
||||||
|
//2 1 2 1
|
||||||
|
//3 1 3 3 1
|
||||||
|
//4 1 4 6 4 1
|
||||||
|
//5 1 5 10 10 5 1
|
||||||
|
//6 1 6 15 20 15 6 1
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn get_row(row_index: i32) -> Vec<i32> {
|
||||||
|
let row_index = row_index as usize;
|
||||||
|
let mut matrix = vec![vec![0; row_index + 2]; row_index + 1];
|
||||||
|
matrix[0][1] = 1;
|
||||||
|
|
||||||
|
for i in 1..=row_index {
|
||||||
|
for j in 1..=i + 1 {
|
||||||
|
matrix[i][j] = matrix[i - 1][j - 1] + matrix[i - 1][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix[row_index][1..].iter().map(|x| *x).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_119() {
|
||||||
|
assert_eq!(vec![1, 3, 3, 1], Solution::get_row(3));
|
||||||
|
assert_eq!(vec![1], Solution::get_row(0));
|
||||||
|
assert_eq!(vec![1, 1], Solution::get_row(1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user