题目
给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。
示例
题解
双指针 简单
class Solution {
public:
bool check(string s,int i,int j){
while(i < j){
if(s[i] == s[j]){
i++;j--;
}
else return false;
}
return true;
}
bool validPalindrome(string s) {
int j = s.size() - 1;
int i = 0;
int count = 0;
while(i < j){
if(s[i] == s[j]){
i++;j--;
}
else{
return check(s,i + 1,j)||check(s,i,j - 1);
}
}
return true;
}
};