<p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;babad&quot;
<strong>Output:</strong> &quot;bab&quot;
<strong>Explanation:</strong> &quot;aba&quot; is also a valid answer.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;cbbd&quot;
<strong>Output:</strong> &quot;bb&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s</code> consist of only digits and English letters.</li>
</ul>

class Solution:
    def longestPalindrome(self, s: str) -> str:
        s=list(s)
        i=0
        palindrome=[]
        list_of_palindromes=[[]]
        while (i<len(s)):
            j=len(s)-1
            c=i
            d=j
            while(j>=0):
                flags=0   
                if (s[i]==s[j]):
                    flags=1
                    a=i
                    b=j
                    c=i
                    d=j
                if(i==j):
                    break
                if (flags==1):
                    while(s[c]==s[d]):
                        palindrome.append(s[c])
                        c+=1
                        d-=1
                        if (c>=len(s) or d<0):
                            break
                    if (b!=c-1 or a!=d+1):
                        while(palindrome):
                            palindrome.pop()
                    
                    if(b==c-1 or a==d+1):
                        list_of_palindromes.append(palindrome)
                        palindrome=[]
                if (c>=len(s) or d<0):
                    break                        
                j-=1
            i+=1

        if len(palindrome) ==0:
            palindrome.append(s[0])
            list_of_palindromes.append(palindrome)

        max = len(list_of_palindromes[0])
        max_index=0
        for i in range(len(list_of_palindromes)):
            if(len(list_of_palindromes[i])>max):
                max=len(list_of_palindromes[i])
                max_index=i
               
        return (''.join(''.join(list_of_palindromes[max_index])))
20900