Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions problems/0516.最长回文子序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,29 @@ func longestPalindromeSubseq(s string) int {
}
```

Javascript:
```javascript
const longestPalindromeSubseq = (s) => {
const strLen = s.length;
let dp = Array.from(Array(strLen), () => Array(strLen).fill(0));

for(let i = 0; i < strLen; i++) {
dp[i][i] = 1;
}

for(let i = strLen - 1; i >= 0; i--) {
for(let j = i + 1; j < strLen; j++) {
if(s[i] === s[j]) {
dp[i][j] = dp[i+1][j-1] + 2;
} else {
dp[i][j] = Math.max(dp[i+1][j], dp[i][j-1]);
}
}
}

return dp[0][strLen - 1];
};
```


-----------------------
Expand Down