Longest Palindromic Substring
Problem statement
Given a string s, return its longest palindromic substring. A substring is a contiguous part of the string, and a palindrome reads the same from left to right and right to left.
If several longest palindromic substrings exist, return the one with the smallest starting index. Compare characters exactly, so uppercase and lowercase letters are different.
Function
longestPalindrome(s: String) → StringExamples
Example 1
s = "babad"return = "bab"Both bab and aba have length 3. The substring bab starts at index 0, earlier than aba at index 1.
Example 2
s = "cbbd"return = "bb"The two middle characters form bb, a palindrome of length 2. No longer substring is a palindrome.
Constraints
1 <= s.length <= 1000.scontains only ASCII English letters and digits.