A palindrome is a string that reads the same from the left and from the right. For example, "mom" and "tacocat" are palindromes, as are any single-character strings. Given a string, determine the number of its substrings that are palindromes.
Example: The string is s = "tacocat". Palindromic substrings are ["t", "a", "c", "o", "c", "a", "t", "coc", "acoca", "tacocat"]. There are 10 palindromic substrings.
Function Description: Complete the countPalindromes function in the editor.
countPalindromes has the following parameter:
- string s: the string to analyze
Returns:
- int: an integer that represents the number of palindromic substrings in the given string
Constraints:
- 1 <= |s| <= 5x10^3
- Each character of s[i] is in the range 'a' to 'z'