12ms c++ solution


  • 0
    C

    bool isPalindrome(string s) {
    int len=s.length();
    int i=0,j=len-1;
    while (i<j){
    if (!isLetter(s[i])&&!isNumber(s[i])){i++; continue;}
    if (!isLetter(s[j])&&!isNumber(s[j])){j--; continue;}
    if (s[i]==s[j]){i++; j--; continue;}
    else if(isLetter(s[i])&&isLetter(s[j])&&abs(s[i]-s[j])=='a'-'A') {i++; j--; continue;}
    return false;
    }
    return true;
    }

    bool isLetter(char c){
    if ((c<='z'&&c>='a')||(c<='Z'&&c>='A'))
    return true;
    else
    return false;
    }
    bool isNumber(char c){
    if (c<='9'&&c>='0')
    return true;
    else
    return false;
    }


Log in to reply
 

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