leetcode647+找出所有子串回文串的总数,暴力

https://leetcode.com/problems/palindromic-substrings/description/

class Solution {
public:
    int countSubstrings(string s) {
        int count = 0;
        for(int i=1; i<=s.size(); i++){
            for(int j=0; j<=s.size()-i; j++){
                string temp = s.substr(j, i);
                string re_temp = temp;
                reverse(re_temp.begin(), re_temp.end());
                if(temp == re_temp) count+=1;
            }
        }
        return count;
    }
};

你可能感兴趣的:(Leetcode)