<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>

import logging

logging.basicConfig(level=logging.INFO)
logger=logging.getLogger()

class Solution:
    def longestPalindrome(self, s: str) -> str:
        logger.debug(f"{s=}")
        if len(s) == 0:
            return ""
        if len(s) == 2 and s[0] == s[1]:
            return s
        longest = s[0]
        curDrome = ""
        for i in range(1,len(s)-1):
            logger.debug(f"{i=}")
            endDist = len(s) - (i+1)
            if (2*endDist)+1 < len(longest):
                logger.debug("NA1")
                return longest
            j = i; k=i

            logger.debug(f"?? : {s[j]=}, {s[i]=}, {s[k]=}")
            while s[j] == s[i]:
                curDrome = s[j:k+1]
                j-=1
                logger.debug(f"1. {curDrome=}")
                if j < 0:
                    logger.debug("b1")
                    break
            while s[i] == s[k]:
                curDrome = s[j+1:k+1]
                k+=1
                logger.debug(f"2. {curDrome=}")
                if k >= len(s):
                    logger.debug("b2")
                    break
            

            if j >= 0 and k < len(s):
                logger.debug(f"3. {j=}, {k=}, {s[j]=}, {s[k]=}")
                if s[j] == s[k]:
                    while True:
                        logger.debug(f"3.2: {j=}, {k=}, {s[j]=}, {s[k]=}")
                        if s[j] == s[k]:
                            curDrome = s[j:k+1]
                            j-=1
                            k+=1
                        else:
                            logger.debug("b3")
                            break
                        if j < 0 or k >= len(s):
                            logger.debug("b4")
                            break
                else:
                    logger.debug("NE")
            logger.debug(f"{curDrome=}")
            if len(curDrome) > len(longest):
                longest = curDrome
                curDrome = ""
                
        return longest


17300