Skip to content

Commit 2a2911e

Browse files
authored
Create task computiq#2
1 parent 67a32aa commit 2a2911e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

task #2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def longestPalindrome(self, s):
3+
"""
4+
:type s: str
5+
:rtype: str
6+
"""
7+
substr = []
8+
9+
i = 0
10+
while i <= len(s) - 2:
11+
j = i + 1
12+
while j <= len(s):
13+
p = s[i:j]
14+
if p[::-1] == s[i:j]:
15+
if len(s[i:j]) > len(substr):
16+
substr = s[i:j]
17+
j += 1
18+
i += 1
19+
if not substr:
20+
return s[0]
21+
return substr

0 commit comments

Comments
 (0)