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;
}
};