leetcode680 C++ 124ms 删掉一个字符后能否构成回文


class Solution {
public:
    bool validPalindrome(string s) {
        int len = s.size();
        if(len<=2){
            return true;
        }
        return judge(s, 0, len-1, 1);
    }
private:
    bool judge(string s, int left, int right, int diff){
        while(left < right){

            if(s[left] != s[right]){
                if(diff == 0 ){
                    return false;
                }
                return judge(s, left+1, right, diff-1) || judge(s, left, right-1, diff-1);
            }
            left++;
            right--;
        }
        return true;
    }
};

posted @ 2018-07-27 13:31  一条图图犬  阅读(281)  评论(0编辑  收藏  举报