C in 3ms


  • 0
    Z
    #include <string.h>
    bool isPalindrome(char* s) {
    if(!s||!*s) return true;
    int i=0,j=strlen(s)-1;
    while(i<j)
    {
        if(s[i]<'0'||(s[i]>'9'&&s[i]<'A')||(s[i]>'Z'&&s[i]<'a')||s[i]>'z') {i++;continue;}
        if(s[j]<'0'||(s[j]>'9'&&s[j]<'A')||(s[j]>'Z'&&s[j]<'a')||s[j]>'z') {j--;continue;}
        if(s[i]>='A'&&s[i]<='Z') s[i]=s[i]-'A'+'a';
        if(s[j]>='A'&&s[j]<='Z') s[j]=s[j]-'A'+'a';
        if(s[i]!=s[j]) return false;
        i++;j--;
    }
    return true;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.