首页 > 代码库 > Valid Palindrome

Valid Palindrome

class Solution {
public:
    bool isPalindrome(string s) {
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        int lt = 0, rt = s.size()-1;
        
        while(lt < s.size() && rt >= 0)
        {
            if(!isalnum(s[lt]))
                ++lt;
            else if(!isalnum(s[rt]))
                --rt;
            else if(s[lt] != s[rt])
                return false;
            else
            {
                ++lt;
                --rt;
            }
        }
        
        return true;
    }
};

 

Valid Palindrome