for Robot Artificial Inteligence

73. Valid Palindrome

|

class Solution {
public:
    bool isPalindrome(string s) {
        vector<char> f;
        for(char c : s)
        {
            if(64<c and c<91 || 96<c and c<123 || 47<c and c<58)
            {
                if(64<c and c<91)
                {
                    c=c+32; // lower alphabet
                }
                f.push_back(c);
            }
        }
        int n = f.size()-1; // total size of
        for(int i = 0, j =n; i<=n; i++,j--)
        {
            if(f[i]!=f[j])
                return false;
        }

        return true;
    }
};

Comments