PROBLEM LINKS
DIFFICULTY
EASY
EXPLANATION
The problem can be solved easily by dynamic programming:
F(i) = CountPal(s') for s' is the subtring of s[1]..s[i]
so F(i) = sum of F(j) with j < i whether the substring of s[j+1]..s[i] is a palindrome.
To verify a substring is a palindrome or not, we can pre-compute to save time of DP.
Complexity: O(|s|^2)