首页 > 代码库 > LeetCode Valid Palindrome

LeetCode Valid Palindrome

class Solution {public:    bool isPalindrome(string s) {        int len = s.length();        //if (len < 1) return true;        int p = -1, q = len;        while (true) {            char a, b;            while (++p < len && !(a = check2lower(s[p])) );            while (--q > -1 && !(b = check2lower(s[q])) );            if (p >= q) return true;            if (a != b) {                return false;            }        }        return true;    }        char check2lower(char ch) {        if (ch <= 9 && ch >= 0) return ch;        if (ch <= z && ch >= a) return ch;        if (ch <= Z && ch >= A) return ch + a - A;        return \0;    }};

跟快排的结构有点类似