Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5166971

Browse files
committed
longest com subseq
1 parentcc30094 commit5166971

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

‎src/longest_common_subseq.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pubstructSolution{}
2+
implSolution{
3+
pubfnlongest_common_subsequence(text1:String,text2:String) ->i32{
4+
letmut dp =vec![vec![0; text2.len() +1]; text1.len() +1];
5+
let t1 = text1.as_bytes();
6+
let t2 = text2.as_bytes();
7+
for iin(0..text1.len()).rev(){
8+
for jin(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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
modunique_paths;
1+
modlongest_common_subseq;
22
fnmain(){}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp