111. Count palindromic substrings

JavaScriptAlgorithm
Is this helpful ?

medium  - accepted / - tried

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.

Let's try to solve this problem within 10 mintues.

Discuss(17)