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 92fcd29 + 811082b commit aad3cd7Copy full SHA for aad3cd7
problems/0005.最长回文子串.md
@@ -270,6 +270,23 @@ public:
270
## Python
271
272
```python
273
+class Solution:
274
+ def longestPalindrome(self, s: str) -> str:
275
+ dp = [[False] * len(s) for _ in range(len(s))]
276
+ maxlenth = 0
277
+ left = 0
278
+ right = 0
279
+ for i in range(len(s) - 1, -1, -1):
280
+ for j in range(i, len(s)):
281
+ if s[j] == s[i]:
282
+ if j - i <= 1 or dp[i + 1][j - 1]:
283
+ dp[i][j] = True
284
+ if dp[i][j] and j - i + 1 > maxlenth:
285
+ maxlenth = j - i + 1
286
+ left = i
287
+ right = j
288
+ return s[left:right + 1]
289
+
290
```
291
292
## Go
0 commit comments