My short c 20 lines solution, O(1) space, and O(n) time ,4ms


  • 0
    X
    #define isstr(a)  ((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
    bool isPalindrome(char* s) {
    if(NULL == s)       return true;
    if('\0' == s)       return true;
    if(strlen(s) < 2)   return true;
    char* pa = s;
    char* pb = s;
    char* l  = s;
    while(*pb != '\0') pb++;
    pb--;
    char* n = pb;
    while(pa < pb)
    {
        while(!isstr(*pa) && pa<=n)  pa++;
        while(!isstr(*pb) && pb>=l)	pb--;
        if(((*pa != *pb) && (abs(*pa-*pb) != 'a'-'A')) && (isstr(*pa)) && (isstr(*pb)))  return false;
    	else
    	{
    		pa++;
    		pb--;
    	}
    }
    return true;
    

    }


Log in to reply
 

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