Skip to content

Commit ec7b5b2

Browse files
Merge pull request seeditsolution#248 from cadwellh5/patch-2
Longest palindrome in a string
2 parents 0daa5c3 + 0d8f8ad commit ec7b5b2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

longestPalindrome

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
t= int(input())
2+
for k in range(t):
3+
str=input()
4+
substring=[]
5+
for i in range(len(str)):
6+
for j in range(i+1,len(str)+1):
7+
substring.append(str[i:j])
8+
pal=[]
9+
for i in range(0,len(substring)):
10+
temp=substring[i]
11+
temp1=temp[::-1]
12+
if (temp==temp1):
13+
pal.append(temp)
14+
max=""
15+
for i in range(0,len(pal)):
16+
if((len(pal[i])>len(max)) and (len(pal[i])>1)):
17+
max=pal[i]
18+
elif(len(max)<=1):
19+
max=pal[0] #max=str[:1]
20+
print(max)
21+
substring.clear()
22+
pal.clear()

0 commit comments

Comments
 (0)