A palindrome reads the same from left to right as from right to left, like level or 7337. Given a string s, return its longest substring that is a palindrome. A substring is a run of consecutive characters of s.
Upper- and lower-case letters are different characters, so Aa is not a palindrome.
kayak mirrors around its middle y. No other run of five or more letters is a palindrome.
A palindrome can have an even length: noon mirrors around the gap between its two os.
The whole string would be a palindrome if case were ignored, but A and a differ, so the answer is the middle bb.
Constraints
1 <= s.length <= 1000s is made of digits and English letters (upper and lower case).Every palindrome mirrors around a centre: a single character (odd length) or the gap between two equal neighbours (even length). A string of length n has only 2n − 1 centres.
Every palindrome has a middle. In level it's the v; in noon it's the gap between the two os. Stand at the middle and step outward one place on each side: as long as the two new letters match, you're still inside a palindrome. The first mismatch, or the edge of the string, tells you exactly how far it reaches.
Time O(n²)Space O(1)
The full walkthrough and code are part of Premium