Skip to content

Commit af80ca6

Browse files
committed
add test
1 parent 78aada2 commit af80ca6

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ members = [
1111
"intersection_of_two_arrays",
1212
"longest_palindromic_substring",
1313
"reverse_words_in_a_string_iii",
14+
"edit_distance",
1415
]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Resolving problems of LeetCode in RustLang.
1111
* [5. Longest Palindromic Substring](./longest_palindromic_substring/lib.rs)
1212
* [7. Reverse Integer](./reverse_integer/src/lib.rs)
1313
* [15. 3 Sum](./three_sum/src/lib.rs)
14+
* [72. Edit Distance](./edit_distance/src/lib.rs)
1415
* [88. Merge Sorted Array](./merge_sorted_array/src/lib.rs)
1516
* [145. Binary Tree Postorder Traversal](./binary_tree_postorder_traversal/src/lib.rs)
1617
* [215. Kth Largest Element in an Array](./kth_largest/src/lib.rs)

edit_distance/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "edit_distance"
3+
version = "0.1.0"
4+
authors = ["Ryan Li <conbas2019@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

edit_distance/src/lib.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*!
2+
* # 72. Edit Distance
3+
*
4+
* [Problem link](https://leetcode.com/problems/edit-distance/)
5+
*/
6+
7+
#![allow(dead_code)]
8+
9+
struct Solution {}
10+
11+
// ----------------------------------------------------------------------------
12+
13+
impl Solution {
14+
pub fn min_distance(word1: String, word2: String) -> i32 {
15+
3
16+
}
17+
}
18+
19+
// ----------------------------------------------------------------------------
20+
21+
#[cfg(test)]
22+
mod tests {
23+
use super::*;
24+
25+
fn accept(word1: &str, word2: &str, expected: i32) {
26+
assert_eq!(
27+
Solution::min_distance(word1.to_string(), word2.to_string()),
28+
expected
29+
);
30+
}
31+
32+
#[test]
33+
fn test_example_1() {
34+
let word1 = "horse";
35+
let word2 = "ros";
36+
let expected = 3;
37+
accept(word1, word2, expected);
38+
}
39+
40+
#[test]
41+
fn test_example_2() {
42+
let word1 = "intention";
43+
let word2 = "execution";
44+
let expected = 5;
45+
accept(word1, word2, expected);
46+
}
47+
}

0 commit comments

Comments
 (0)