Compare commits
29
Commits
93d4b712d5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
551db6decf | ||
|
|
c1fe8fd658 | ||
|
|
23a4622f11 | ||
|
|
ebd3f9445c | ||
|
|
50fba25511 | ||
|
|
ece3af5149 | ||
|
|
a19c7573a7 | ||
|
|
fe0577dd06 | ||
|
|
fcf3f21a52 | ||
|
|
cb73a780cf | ||
|
|
86ec2ee252 | ||
|
|
fc8857537e | ||
|
|
8cc7ce864c | ||
|
|
b88bfb137b
|
||
|
|
985c978958
|
||
|
|
25645920ff
|
||
|
|
44ce8b9fd4
|
||
|
|
afa91fe380
|
||
|
|
6e59cabd84
|
||
|
|
00bc762b5e
|
||
|
|
9452c4e658 | ||
|
|
a9da2f1227
|
||
|
|
fa937a142f
|
||
|
|
6213d83856
|
||
|
|
d0da066c58
|
||
|
|
4460a2f028
|
||
|
|
4ee2acd245
|
||
|
|
6074be16ce
|
||
|
|
11a7d6775d
|
+18
-40
@@ -1,51 +1,29 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use std::collections::hash_map::Entry;
|
|
||||||
|
|
||||||
mod arr;
|
mod arr;
|
||||||
|
|
||||||
struct Solution {}
|
struct Solution {}
|
||||||
impl Solution {
|
impl Solution {
|
||||||
fn get_rev(t: i32) -> i32 {
|
pub fn min_distance(word1: String, word2: String) -> i32 {
|
||||||
let mut t = t;
|
let mut dp = vec![vec![0; word2.len() + 1]; word1.len() + 1];
|
||||||
let mut ans = 0;
|
let word1 = word1.chars().collect::<Vec<char>>();
|
||||||
while t > 0 {
|
let word2 = word2.chars().collect::<Vec<char>>();
|
||||||
ans = ans * 10 + (t % 10);
|
for i in 1..=word1.len() {
|
||||||
t /= 10;
|
dp[i][0] = dp[i - 1][0] + 1;
|
||||||
}
|
}
|
||||||
ans
|
for i in 1..=word2.len() {
|
||||||
|
dp[0][i] = dp[0][i - 1] + 1;
|
||||||
}
|
}
|
||||||
pub fn min_mirror_pair_distance(nums: Vec<i32>) -> i32 {
|
for i in 0..word1.len() {
|
||||||
let mut map = HashMap::<i32, Vec<usize>>::new();
|
for j in 0..word2.len() {
|
||||||
for i in 0..nums.len() {
|
dp[i + 1][j + 1] = (dp[i][j] + if word1[i] != word2[j] { 1 } else { 0 })
|
||||||
map.entry(nums[i]).or_insert_with(Vec::new).push(i);
|
.min(dp[i][j + 1] + 1)
|
||||||
}
|
.min(dp[i + 1][j] + 1);
|
||||||
let mut ans = 1e9 as usize;
|
|
||||||
for i in 0..nums.len() {
|
|
||||||
let x = nums[i];
|
|
||||||
match map.entry(Self::get_rev(x)) {
|
|
||||||
Entry::Occupied(arr) => {
|
|
||||||
//ans = ans.max(i.abs_diff(*arr.get().last().unwrap())).max(i.abs_diff(*arr.get().first().unwrap()));
|
|
||||||
let arr = arr.get();
|
|
||||||
if arr.len() == 1 {
|
|
||||||
if i != arr[0] && arr[0] > i {
|
|
||||||
ans = ans.min(arr[0] - i);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let idx = arr.partition_point(|y| i >= *y);
|
|
||||||
if idx < arr.len() {
|
|
||||||
if i != arr[idx] {
|
|
||||||
ans = ans.min(arr[idx] - i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
dp[word1.len()][word2.len()]
|
||||||
Entry::Vacant(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ans == 1e9 as usize { -1 } else { ans as i32 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{:?}", Solution::min_mirror_pair_distance(vec![9,9]));
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
Solution::min_distance("intention".to_string(), "execution".to_string())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user