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:
- 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=0; int way=0; for(i=0,j=n-1;i<j;i++,j--){ if(s[i]==s[j]) continue; else{ if(way==2){ return false; } if(way==1){ way++; i=si; j=sj; j++; } if(way==0){ way++; count=1; si=i; sj=j; i--; } } } return true; } };
(判断是否回文)