<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 {
public:
    bool checkPalindrome(string str)
    {
        if (!str .size())
        {
            return true;
        }
        int sz = str.size();
        for (int i = 0; i <= sz / 2 - 1 ; i++)
        {
            if (str[i] != str[sz - i - 1])
            {
                return false;
            }
        }
        return true;
    }
    string longestPalindrome(string s) {
        int sz = s.size();
        string result = "";
        result += (s[0]);
        if (sz == 1)
        {
            return result;
        }
        for (int i = 0; i < sz - 1; i++)
        {
            string niceTry(1, s[i]); 
            for (int j = i + 1; j < sz; j++)
            {
                niceTry += s[j];
                if (niceTry[0] != niceTry[niceTry.size() - 1])
                {
                    continue;
                }
                if (result.size() <= niceTry.size() && checkPalindrome(niceTry))
                {
                    result = niceTry;
                }
            }
        }

        return result;
    }

};
410075