Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
leetcode: finished #516
Browse files Browse the repository at this point in the history
  • Loading branch information
xqm32 committed Aug 31, 2023
1 parent 8ff5b84 commit 46ba9ed
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions content/leetcode/2023/8.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ title: "2023.8"
draft: false
---

# 2023.8.31

```python
#
# @lc app=leetcode.cn id=516 lang=python3
#
# [516] 最长回文子序列
#

# @lc code=start
class Solution:
def longestPalindromeSubseq(self, s: str) -> int:
if not s:
return 0
n = len(s)
dp = [[0]*n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for i in range(n-2, -1, -1):
for j in range(i+1, n):
if s[i]==s[j]:
dp[i][j] = dp[i+1][j-1]+2
else:
dp[i][j] = max(
dp[i+1][j],
dp[i][j-1]
)
return dp[0][n-1]
# @lc code=end
```

# 2023.8.30

```python
Expand Down

0 comments on commit 46ba9ed

Please sign in to comment.