parent
633f086f89
commit
811082be57
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue