class Solution {
public:
bool isPalindrome(string s) {
if(s.length()==0)return true;
else{
string ss=parser(s);
int i=0;
int j=ss.length()-1;
while(i<=j){
if(ss[i]==ss[j]||abs(int(ss[i]-ss[j]))==('a'-'A')){
++i;
--j;
}
else break;
}
if(i>j)return true;
else return false;
}
}
string parser(string s){
string res;
for(int i=0;i<s.length();++i){
if('a'<=s[i]&&s[i]<='z'||'0'<=s[i]&&s[i]<='9'||'A'<=s[i]&&s[i]<='Z'){
res.append(1,s[i]);
}
}
return res;
}
};
No comments:
Post a Comment