125. Valid Palindrome

来源:互联网 发布:查手机mac地址 编辑:程序博客网 时间:2024/06/06 07:25
class Solution {public:    bool isPalindrome(string s) {        string::iterator low = s.begin(), high = s.end() - 1;        while(low < high){            while(!isUpCh(*low) && !isDwnCh(*low) && !isNum(*low)) ++low;            while(!isUpCh(*high) && !isDwnCh(*high) && !isNum(*high)) --high;            if(low >= high)                break;            if(*low != *high){                if(isCh(*low) && isCh(*high)){                    if(*low - *high == 32 || *high - *low == 32){                        ++low; --high; continue;                    }                }                return false;            }            ++low; --high;        }        return true;    }    bool isCh(char c){        return (c>=97 && c<=122) || (c>=65 && c<=90);    }    bool isUpCh(char c){        return c>=97 && c<=122;    }    bool isDwnCh(char c){        return c>=65 && c<=90;    }    bool isNum(char c){        return c>=48 && c<=57;    }};

原创粉丝点击