leetcode valid palindrome

判断是否回文

class Solution {
public:
    bool isPalindrome(string s) 
    {
        if(s=="")return true;
        for(int i=0,j=s.size()-1;i<j;)
        {
            while(!isalpha(s[i])&&i<j&&!isdigit(s[i]))i++;
            while(!isalpha(s[j])&&i<j&&!isdigit(s[j]))j--;
            if(tolower(s[i])==tolower(s[j])||s[i]==s[j])
            {
                i++,j--;
            }
            else return false;
        }
        return true;
    }
};

 

posted @ 2013-05-22 14:29  代码改变未来  阅读(183)  评论(0编辑  收藏  举报