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.
2 parents 9555e08 + 80dda7a commit dc531fdCopy full SHA for dc531fd
problems/0516.最长回文子序列.md
@@ -214,7 +214,29 @@ func longestPalindromeSubseq(s string) int {
214
}
215
```
216
217
+Javascript:
218
+```javascript
219
+const longestPalindromeSubseq = (s) => {
220
+ const strLen = s.length;
221
+ let dp = Array.from(Array(strLen), () => Array(strLen).fill(0));
222
+
223
+ for(let i = 0; i < strLen; i++) {
224
+ dp[i][i] = 1;
225
+ }
226
227
+ for(let i = strLen - 1; i >= 0; i--) {
228
+ for(let j = i + 1; j < strLen; j++) {
229
+ if(s[i] === s[j]) {
230
+ dp[i][j] = dp[i+1][j-1] + 2;
231
+ } else {
232
+ dp[i][j] = Math.max(dp[i+1][j], dp[i][j-1]);
233
234
235
236
237
+ return dp[0][strLen - 1];
238
+};
239
+```
240
241
242
-----------------------
0 commit comments