跳至主要内容

125. 验证回文串

class Solution {
public:
   
    bool isValid(char c)
    {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
        {
            return true;
        }
        return false;
    }
   
    bool isPalindrome(string s) {
        int i = 0;
        int j = s.length() - 1;
        while (i < j)
        {
            if (!isValid(s[i]))
            {
                i++;
                continue;
            }
            if (!isValid(s[j]))
            {
                j--;
                continue;
            }
            if (tolower(s[i]) != tolower(s[j]))
            {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
};

评论

此博客中的热门博文