111. Count palindromic substrings

Is this helpful ?

from all members: - 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:


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.