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 81f74d8 commit c43355dCopy full SHA for c43355d
problems/1143.最长公共子序列.md
@@ -197,7 +197,24 @@ func max(a,b int)int {
197
}
198
```
199
200
+Javascript:
201
+```javascript
202
+const longestCommonSubsequence = (text1, text2) => {
203
+ let dp = Array.from(Array(text1.length+1), () => Array(text2.length+1).fill(0));
204
+
205
+ for(let i = 1; i <= text1.length; i++) {
206
+ for(let j = 1; j <= text2.length; j++) {
207
+ if(text1[i-1] === text2[j-1]) {
208
+ dp[i][j] = dp[i-1][j-1] +1;;
209
+ } else {
210
+ dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1])
211
+ }
212
213
214
215
+ return dp[text1.length][text2.length];
216
+};
217
+```
218
219
220
-----------------------
0 commit comments