求字符串有多少个回文子串
不好理解
class Solution {
public:
int countSubstrings(string s) {
int n = s.size(), sum = 0;
for(int i = 0; i < n*2-1; i++)
{
int l = i / 2, r = i/2 + i%2;
while(l>=0 && r < n && s[l] == s[r])
{
l--;
r++;
sum++;
}
}
return sum;
}
};