Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
For example,
"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.
class Solution {
public:
bool isPalindrome(string s) {
int l=s.length();
char a1[l],c1=0;
for(int i=0;i<l;i++)
if((s.at(i)>=97&&s.at(i)<=122)||(s.at(i)>=65&&s.at(i)<=90)||(s.at(i)>=48&&s.at(i)<=57))
{
a1[c1++]=s.at(i);
if(s.at(i)>=97)
a1[c1-1]-=32;
}
a1[c1]='\0';
int l1=0,h=c1-1;
char a2[c1];
for(int i=0,j=c1-1;i<c1;i++,j--)
a2[i]=a1[j];
a2[c1]=0;
if(!strcmp(a1,a2))
return true;
return false;
}
};

No comments:
Post a Comment