class Solution {
public:
int countSubstrings(string s) {
vector<string> res;
for(int i = 0;i < s.length();i++){
for(int j = 1;j <= s.length() - i;j++){
if(isPalindrome(s.substr(i,j))){
res.push_back(s.substr(i,j));
}
}
}
return res.size();
}
bool isPalindrome(string str){
bool ans = true;
for(int i = 0,j = str.length() - 1;i < j;i++,j--){
if(str[i] != str[j]){
ans = false;
break;
}
}
return ans;
}
};
leetcode 647. 回文子串
最新推荐文章于 2025-12-14 19:30:20 发布
384

被折叠的 条评论
为什么被折叠?



