String-680. Valid Palindrome II

时间:2023-03-10 04:30:34
String-680. Valid Palindrome II

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

Example 1:

Input: "aba"
Output: True

Example 2:

Input: "abca"
Output: True
Explanation: You could delete the character 'c'.

Note:

  1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
class Solution {
public:
bool validPalindrome(string s) {
int i,j;
int si,sj;
int n=s.size();
int count=;
int way=;
for(i=,j=n-;i<j;i++,j--){
if(s[i]==s[j])
continue;
else{
if(way==){
return false;
}
if(way==){
way++;
i=si;
j=sj;
j++;
}
if(way==){
way++;
count=;
si=i;
sj=j;
i--;
}
}
}
return true;
}
};

(判断是否回文)