20250128 finished.

This commit is contained in:
jackfiled 2025-01-28 11:59:05 +08:00
parent 70883c231b
commit 4358c2555c
3 changed files with 48 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View 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));
}
}