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 8440a1d commit 8684a5eCopy full SHA for 8684a5e
1 file changed
longest-palindromic-substring/ppxyn1.py
@@ -0,0 +1,27 @@
1
+#idea: -
2
+#Time Complexity: O(n^2)
3
+class Solution:
4
+ def longestPalindrome(self, s: str) -> str:
5
+ ans = ''
6
+ def check_func(l, r):
7
+ while l >= 0 and r < len(s):
8
+ if s[l] != s[r]:
9
+ break
10
+ l -= 1
11
+ r += 1
12
+ return s[l+1:r]
13
+
14
+ for i in range(len(s)):
15
+ odd = check_func(i, i)
16
+ even = check_func(i, i+1)
17
+ if len(odd) > len(even):
18
+ longer = odd
19
+ else:
20
+ longer = even
21
22
+ if len(longer) > len(ans):
23
+ ans = longer
24
25
+ return ans
26
27
0 commit comments