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 52dfd63 commit 04fcf31Copy full SHA for 04fcf31
1 file changed
longest-palindromic-substring/doh6077.py
@@ -0,0 +1,30 @@
1
+# 5. Longest Palindromic Substring
2
+# https://leetcode.com/problems/longest-palindromic-substring/
3
+
4
5
+class Solution:
6
+ def longestPalindrome(self, s: str) -> str:
7
+ #Expand Around Center
8
+ res = ""
9
+ resLen = 0
10
11
+ for i in range(len(s)):
12
+ # odd length
13
+ l, r = i, i
14
+ while l >= 0 and r < len(s) and s[l] == s[r]:
15
+ if (r - l + 1) > resLen:
16
+ res = s[l:r+1]
17
+ resLen = r - l + 1
18
+ l -= 1
19
+ r += 1
20
21
+ # even length
22
+ l, r = i, i + 1
23
24
25
26
27
28
29
30
+ return res
0 commit comments