<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:
        #find all centers and add to DP array
        DP = []
        for i in range(len(s)):
            if(i>0):
                if(s[i-1] == s[i]):
                    DP.append(((i-1,i),s[i-1]+s[i]))
            DP.append((i,s[i]))
        
        
        
        

        #expand each center
        for i in range(len(DP)):
            index = DP[i][0]
            #check if double index
            if not isinstance(index, int):
                index1 = index[0]
                index2 = index[1]
            else:
                index1 = index
                index2 = index
            index1 -=1
            index2 +=1
            while(index1 >=0 and index2<len(s)):
                if s[index1] == s[index2]:
                    if isinstance(DP[i], tuple):
                        DP[i] = s[index1] + DP[i][1] + s[index2]
                    else:
                        DP[i] = s[index1] + DP[i] + s[index2]
                    index1 -=1
                    index2 +=1
                else:
                    break
        #remove other values
        for i in range(len(DP)):
            if isinstance(DP[i], tuple):
                DP[i] = DP[i][1]

        print(DP)
        #find longest palindrome
        longestPal = DP[0]
        longestLen = 1
        for palin in DP:
            if len(palin) > longestLen:
                longestLen = len(palin)
                longestPal = palin
        
        return longestPal
                 
        

                

                
            
20100