Given a string s, return the longest contiguous substring of s that is a palindrome. If several palindromic substrings tie for the longest length, return the one that starts earliest in s. This tie-break makes the answer unique.
Characters are case-sensitive: "Aa" is not a palindrome.
Examples
Example 1
Input: s = "babad"
Output: "bab"
Explanation: "bab" and "aba" both have length 3; "bab" starts earlier.
Example 2
Input: s = "cbbd"
Output: "bb"
Constraints
1≤s.length≤1000
s consists of digits and English letters.
Examples
Example 1
Input
s = "babad"
Output
"bab"
Example 2
Input
s = "cbbd"
Output
"bb"
Loading editor...
Click "Run" to test with sample cases or "Submit" to run all tests.