My accepted 12ms C++ Code


  • 0
    S
    class Solution {
    public:
        bool validchar(char a){
            return a>='A'&&a<='Z'||a>='a'&&a<='z'||a>='0'&&a<='9';
        }
        bool isPalindrome(string s) {
            int n=s.size();
            int front=0, rear=n-1;
            while(front<rear){
                if(!validchar(s[front])) front++;
                else if(!validchar(s[rear])) rear--;
                else if(s[front]==s[rear]||s[front]-'A'==s[rear]-'a'||s[front]-'a'==s[rear]-'A'){
                    front++;
                    rear--;
                }
                else return false;
            }
            return true;
        }
    };

Log in to reply
 

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