We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 0daa5c3 + 0d8f8ad commit ec7b5b2Copy full SHA for ec7b5b2
1 file changed
longestPalindrome
@@ -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