class Solution {
public boolean validPalindrome(String s) {
int n=s.length();
char[]cs=s.toCharArray();
if(n==1) return true;
int l=0;
int r=n-1;
while(l<r){
if(cs[l]==cs[r]){
l++;
r--;
}else{
return judge(cs,l,r-1)||judge(cs,l+1,r);
}
}
return true;
}
public boolean judge(char[]cs,int l,int r){
int len=r-l+1;
if(len==1) return true;
while(l<r){
if(cs[l]!=cs[r]) return false;
l++;
r--;
}
return true;
}
}
寒假-每日一题-day 05
最新推荐文章于 2022-01-07 23:36:38 发布