bool isPalindrome(char * s)
{
int i,j;
int len = strlen(s);
char *p = (char*)malloc(sizeof(char)*(len));
for(i=0,j=0;s[i]!='\0';i++)
{
if(s[i]>='0' && s[i]<='9' || (s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z'))
{
if(s[i]>='A' && s[i]<='Z')
{
p[j++] = s[i] +32;
}
else p[j++] = s[i];
}
}
for(i=0,j--;i<j;i++,j--)
{
if(p[i]!=p[j])
{
free(p);
return false;
}
}
free(p);
return true;
}
力扣 125.验证回文串
最新推荐文章于 2022-09-29 11:56:58 发布