mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
@ -270,6 +270,23 @@ public:
|
||||
## Python
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def longestPalindrome(self, s: str) -> str:
|
||||
dp = [[False] * len(s) for _ in range(len(s))]
|
||||
maxlenth = 0
|
||||
left = 0
|
||||
right = 0
|
||||
for i in range(len(s) - 1, -1, -1):
|
||||
for j in range(i, len(s)):
|
||||
if s[j] == s[i]:
|
||||
if j - i <= 1 or dp[i + 1][j - 1]:
|
||||
dp[i][j] = True
|
||||
if dp[i][j] and j - i + 1 > maxlenth:
|
||||
maxlenth = j - i + 1
|
||||
left = i
|
||||
right = j
|
||||
return s[left:right + 1]
|
||||
|
||||
```
|
||||
|
||||
## Go
|
||||
|
Reference in New Issue
Block a user