Compare commits
45
Commits
60447f6bf8
..
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
|
||
|
|
93d4b712d5
|
||
|
|
a467de459b
|
||
|
|
653e68c8f1
|
||
|
|
671347dfde
|
||
|
|
023fe9ec14
|
||
|
|
a6ca63686a
|
||
|
|
283b4c1518
|
||
|
|
444863b22d
|
||
|
|
8cac824082
|
||
|
|
8cc2ab780c
|
||
|
|
98eafcac0e
|
||
|
|
ecb53e3f3a
|
||
|
|
cca3dc4a88
|
||
|
|
8a381984c9 | ||
|
|
d7f5b98838 | ||
|
|
f1f47604f8 |
+20
-34
@@ -1,43 +1,29 @@
|
|||||||
struct Solution;
|
|
||||||
mod arr;
|
mod arr;
|
||||||
|
struct Solution {}
|
||||||
impl Solution {
|
impl Solution {
|
||||||
fn is_same(mat: &Vec<Vec<i32>>, target: &Vec<Vec<i32>>) -> bool {
|
pub fn min_distance(word1: String, word2: String) -> i32 {
|
||||||
for i in 0..mat.len() {
|
let mut dp = vec![vec![0; word2.len() + 1]; word1.len() + 1];
|
||||||
for j in 0..mat[i].len() {
|
let word1 = word1.chars().collect::<Vec<char>>();
|
||||||
if mat[i][j] != target[i][j] {
|
let word2 = word2.chars().collect::<Vec<char>>();
|
||||||
return false;
|
for i in 1..=word1.len() {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
dp[word1.len()][word2.len()]
|
||||||
true
|
|
||||||
}
|
|
||||||
pub fn find_rotation(mat: Vec<Vec<i32>>, target: Vec<Vec<i32>>) -> bool {
|
|
||||||
let mut v = vec![vec![0; mat[0].len()]; mat.len()];
|
|
||||||
if Solution::is_same(&mat, &target) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for x in 1..4 {
|
|
||||||
for i in 0..mat.len() {
|
|
||||||
for j in 0..mat[i].len() {
|
|
||||||
let (mut py, mut px) = (i, j);
|
|
||||||
for _ in 0..x {
|
|
||||||
(px, py) = (mat.len() - 1 - py, px)
|
|
||||||
}
|
|
||||||
v[py][px] = mat[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if Self::is_same(&v, &target) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = Solution::find_rotation(
|
println!(
|
||||||
arr::make_matrix(r#"[[1,0,0],[1,0,1],[0,0,1]]"#),
|
"{:?}",
|
||||||
arr::make_matrix(r#"[[0,1,1],[0,0,0],[1,1,0]]"#),
|
Solution::min_distance("intention".to_string(), "execution".to_string())
|
||||||
);
|
);
|
||||||
println!("{:?}", result);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user