Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string.
Example 1
Input: s = aaa
Output: 6
Explanation: The palindromic substrings are the three single a's, the two overlapping "aa"s and "aaa" itself: 3 + 2 + 1 = 6.
Example 2
Input: s = abc
Output: 3
Explanation: Only the three single letters are palindromes; "ab", "bc" and "abc" are not.
Example 3
Input: s = a
Output: 1
Explanation: The single letter "a" is the only substring, and it is a palindrome.
Every palindrome has a center. There are 2n-1 possible centers (each character and each gap between characters); expand outward from each and count how far it stays a palindrome.
Run checks all cases above. Submit evaluates all test cases.