Count Palindromic Substrings
Problem statement
Given a string text, return the number of palindromic substrings in it.
A palindrome reads the same forward and backward. Substrings are counted by their positions, so equal text appearing at different positions contributes more than once. Every one-character substring is a palindrome.
Function
countPalindromicSubstrings(text: String) → intExamples
Example 1
text = "abc"return = 3The palindromic substrings are "a", "b", and "c".
Example 2
text = "aaa"return = 6There are three one-character palindromes, two occurrences of "aa", and one "aaa".
Constraints
1 <= text.length <= 2000.textcontains lowercase English letters only.