A palindrome reads the same from left to right and from right to left. Given a string s, return its longest palindromic substring. A substring is a continuous part of the string.
Sometimes two palindromes tie for the longest length. In that case answer with the leftmost one, the one with the smaller start position. The expected answer is one fixed string, so this tie rule is part of the problem.
Examples
Example 1:
Input: s = "cabbad"
Output: "abba"
Explanation: "abba" is a palindrome of length 4. No longer palindrome exists.
Example 2:
Input: s = "noonabba"
Output: "noon"
Explanation: "noon" and "abba" both have length 4. "noon" starts first, so it is the answer.
Example 3:
Input: s = "z"
Output: "z"
Explanation: One letter is a palindrome.