20241013 finished.

This commit is contained in:
jackfiled 2024-10-14 11:40:39 +08:00
parent 84e76d7224
commit 468ef5e7a7
2 changed files with 38 additions and 1 deletions

View File

@ -261,4 +261,5 @@ mod p1436_destination_city;
mod p3171_find_subarray_with_bitwise_or_closest_to_k;
mod p3162_find_the_number_of_good_pairs_i;
mod p3164_find_the_number_of_good_pairs_ii;
mod p3158_find_the_xor_of_numbers_which_appear_twice;
mod p3158_find_the_xor_of_numbers_which_appear_twice;
mod p1884_egg_drop_with_2_eggs_and_n_floors;

View File

@ -0,0 +1,36 @@
/**
* [1884] Egg Drop With 2 Eggs and N Floors
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn two_egg_drop(n: i32) -> i32 {
let n = n as usize;
let mut dp = vec![usize::MAX / 2; n + 1];
dp[0] = 0;
for i in 1..=n {
for j in 1..=i {
dp[i] = dp[i].min(j.max(dp[i - j] + 1))
}
}
dp[n] as i32
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1884() {
assert_eq!(2, Solution::two_egg_drop(2));
assert_eq!(14, Solution::two_egg_drop(100));
}
}