class Solution {
public:
int countSubstrings(string s) {
vector<vector<bool>> dp(s.length(), vector<bool>(s.length(),false));
int count = 0;
for(int i = s.length() - 1; i >= 0 ; i--){
for(int j = i; j < s.length(); j++){
if(s[i] == s[j]){
if(j - i <= 1){
count++;
dp[i][j] = true;
}
else if(dp[i + 1][j - 1]){
count++;
dp[i][j] = true;
}
}
}
}
return count;
}
};
05-19
229
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-24
895
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-27