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 8c46d00 commit 0fbc611Copy full SHA for 0fbc611
longest-palindromic-substring/hu6r1s.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def longestPalindrome(self, s: str) -> str:
3
+ # if len(s) <= 2:
4
+ # return s[0]
5
+
6
+ # for i in range(2, len(s)):
7
+ # for k in range(len(s)-i):
8
+ # if s[k:k+i] == s[k:k+i][::-1]:
9
+ # return s[k:k+i]
10
11
+ max_s, max_e = 0, 0
12
13
+ for i in range(len(s)):
14
+ start, end = i, i
15
+ while 0 <= start and end < len(s) and s[start] == s[end]:
16
+ if max_e - max_s < end - start:
17
+ max_s, max_e = start, end
18
+ start, end = start - 1, end + 1
19
20
+ start, end = i, i + 1
21
22
23
24
25
26
+ return s[max_s : max_e + 1]
0 commit comments