Compare commits

..
7 Commits
Author SHA1 Message Date
li_chx 551db6decf 72. 编辑距离 2026-08-13 11:16:29 +08:00
li_chx c1fe8fd658 215. 数组中的第K个最大元素 2026-08-13 10:29:17 +08:00
li_chx 23a4622f11 1510. 石子游戏 IV 2026-08-13 10:29:03 +08:00
li_chx ebd3f9445c 1406. 石子游戏 III 2026-08-13 10:28:46 +08:00
li_chx 50fba25511 877. 石子游戏 2026-08-13 10:28:19 +08:00
li_chx ece3af5149 2996. 大于等于顺序前缀和的最小缺失整数 2026-08-13 10:27:10 +08:00
li_chx a19c7573a7 2958. 最多 K 个重复元素的最长子数组 2026-08-13 10:27:08 +08:00
+17 -16
View File
@@ -1,28 +1,29 @@
use std::collections::HashSet;
mod arr; mod arr;
struct Solution {} struct Solution {}
impl Solution { impl Solution {
pub fn missing_integer(nums: Vec<i32>) -> i32 { pub fn min_distance(word1: String, word2: String) -> i32 {
let mut st = nums.clone().into_iter().collect::<HashSet<i32>>(); let mut dp = vec![vec![0; word2.len() + 1]; word1.len() + 1];
let mut sum = nums[0]; let word1 = word1.chars().collect::<Vec<char>>();
for i in 1 .. nums.len() { let word2 = word2.chars().collect::<Vec<char>>();
if nums[i] != nums[i-1] + 1 { for i in 1..=word1.len() {
break; dp[i][0] = dp[i - 1][0] + 1;
}
for i in 1..=word2.len() {
dp[0][i] = dp[0][i - 1] + 1;
}
for i in 0..word1.len() {
for j in 0..word2.len() {
dp[i + 1][j + 1] = (dp[i][j] + if word1[i] != word2[j] { 1 } else { 0 })
.min(dp[i][j + 1] + 1)
.min(dp[i + 1][j] + 1);
} }
sum += nums[i];
} }
while st.contains(&sum) { dp[word1.len()][word2.len()]
sum += 1;
}
sum
} }
} }
fn main() { fn main() {
// 1 2 2 3
// 0 -1 0 1 0
println!( println!(
"{:?}", "{:?}",
Solution::missing_integer(vec![14,9,6,9,7,9,10,4,9,9,4,4]) Solution::min_distance("intention".to_string(), "execution".to_string())
); );
} }