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.
1 parent 3fd7e0b commit 381f54eCopy full SHA for 381f54e
longest-palindromic-substring/evan.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def longestPalindrome(self, s: str) -> str:
3
+ if not s:
4
+ return ""
5
+
6
+ start, end = 0, 0
7
8
+ def expand_and_get_length(s, left, right):
9
+ while left >= 0 and right < len(s) and s[left] == s[right]:
10
+ left -= 1
11
+ right += 1
12
13
+ return right - left - 1
14
15
+ for i in range(len(s)):
16
+ odd_palindrome_length = expand_and_get_length(s, i, i)
17
+ even_palindrome_length = expand_and_get_length(s, i, i + 1)
18
19
+ max_len = max(odd_palindrome_length, even_palindrome_length)
20
21
+ if max_len > end - start:
22
+ start = i - (max_len - 1) // 2
23
+ end = i + max_len // 2
24
25
+ return s[start : end + 1]
0 commit comments