Skip to content

Commit 8684a5e

Browse files
committed
[:solved] #266
1 parent 8440a1d commit 8684a5e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)