leetcode 647. 回文子串

代码:

class Solution {
    int n,res = 0;
public:

    void help(string&s,int left,int right)
    {
        while(left>=0&&right<n)
        {
            if(s[left--]==s[right++])
            {
                ++res;
            }
            else
            {
                break;
            }
        }
    }
    int countSubstrings(string s) {
        n = s.size();
        for(int i = 0;i<n;++i)
        {
            help(s,i,i);
            help(s,i,i+1);
        }
        return res;
    }
};

 

posted @ 2021-09-26 16:16  A-inspire  Views(16)  Comments(0Edit  收藏  举报