We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc30094 commit 5166971Copy full SHA for 5166971
src/longest_common_subseq.rs
@@ -0,0 +1,18 @@
1
+pub struct Solution {}
2
+impl Solution {
3
+ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
4
+ let mut dp = vec![vec![0; text2.len() + 1]; text1.len() + 1];
5
+ let t1 = text1.as_bytes();
6
+ let t2 = text2.as_bytes();
7
+ for i in (0..text1.len()).rev() {
8
+ for j in (0..text2.len()).rev() {
9
+ if t1[i] == t2[j] {
10
+ dp[i][j] = 1 + dp[i + 1][j + 1];
11
+ } else {
12
+ dp[i][j] = std::cmp::max(dp[i][j + 1], dp[i + 1][j]);
13
+ }
14
15
16
+ dp[0][0]
17
18
+}
src/main.rs
@@ -1,2 +1,2 @@
-mod unique_paths;
+mod longest_common_subseq;
fn main() {}
0 commit comments