leetcode:Valid Palindrome (isPalindrome)

leetcode:Valid Palindrome

bool isPalindrome(string s) {
    if (s.empty())
        return true;
    int l = 0, r = s.size() - 1;
    if (l == r && tolower(s[l]) == tolower(s[r]))
        return true;
    while(l < r) {
        if (isblank(s[l]) || ispunct(s[l])) {
            l++;
            continue;
        }
        if (isblank(s[r]) || ispunct(s[r])) {
            r--;
            continue;
        }
        if (tolower(s[l]) == tolower(s[r])) {
            if(l == r || r -l == 1)
                return true;
            l++;
            r--;
        }
        else
            return false;
    }
    if (l == r)
        return true;
    return false;
}
posted @ 2014-10-21 23:13  mykelia  阅读(123)  评论(0编辑  收藏  举报