Count palindromic substrings
2022年5月1日小于 1 分钟
Count palindromic substrings
Question
A palindromic string reads the same backward as forward, such as 'madam'
.
Now given a string, count how many substrings it has?
Like 'madam'
, it has following palindromic strings:
'm'
'a'
'd'
'a'
'm'
'ada'
'madam'
What is the time and space cost of your solution ? Could you improve it ?
Thanks to @TechieQian for helping with the test cases.
Code
/**
* @param {string} str
* @return {number}
*/
function countPalindromicSubstr(str) {
// your code here
}