leetcode-----125. 验证回文串

算法

时间复杂度:\(O(logn)\)

代码

class Solution {
public:
    bool isalpha(char c) {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return true;
        else return false;
    }

    bool isdigit(int c) {
        if (c >= '0' && c <= '9') return true;
        else return false;
    }


    bool isPalindrome(string s) {
        if (s == "") return true;
        int i = 0, j = s.size() - 1;
        while (i < j) {
            if (!isalpha(s[i]) && !isdigit(s[i])) {
                i++;
                continue;
            }
            if (!isalpha(s[j]) && !isdigit(s[j])) {
                j--;
                continue;
            }

            if (toupper(s[i]) != toupper(s[j])) return false;
            i++, j--;
        }
        return true;
    }
};
上一篇:SpringBoot表单参数验证


下一篇:saleor的测试用账户地址"This value is not valid for the address"