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

Commit640f862

Browse files
committed
Added JS 1143 Longest Common Subsequence
1 parent6f46719 commit640f862

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
varlongestCommonSubsequence=function(text1,text2){
2+
letm=text1.length;
3+
letn=text2.length;
4+
5+
lettable=newArray(m+1).fill().map(()=>newArray(n+1).fill(0));
6+
7+
for(leti=1;i<=m;i++){
8+
for(letj=1;j<=n;j++){
9+
if(text1.charAt(i-1)!==text2.charAt(j-1)){
10+
11+
table[i][j]=Math.max(table[i-1][j],table[i][j-1]);
12+
}else{
13+
table[i][j]=table[i-1][j-1]+1;
14+
}
15+
}
16+
}
17+
returntable[m][n];
18+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp