qingcheng奕  

http://oj.leetcode.com/problems/valid-palindrome/

判断是否为回文串

    bool isPalindrome(string s) {
        int i = 0,j = s.length() -1;
        int flag = 0;

        if(s=="")
            return true;
        
        while(i<=j)
        {
            while(!('a'<= s[i] && s[i]<= 'z' || 'A' <= s[i] && s[i] <='Z' || s[i]>= '0'&&s[i]<='9') || s[i] == ' ' )
            {
                if(i== s.length())
                    break;
                i++;
            }
            while(!('a'<= s[j] && s[j]<= 'z' || 'A' <= s[j] && s[j] <='Z' || s[j]>= '0'&&s[j]<='9') || s[j] == ' ')
            {
                if(j==0)
                    break;
                j--;
            }
            if(toupper(s[i]) != toupper(s[j]) && i<=j)
            {
                flag = 1;
                break;
            }
            i++;
            j--;
        }
        if(flag == 1)
            return false;
        else
            return true;
    }

 

posted on 2014-02-14 11:04  qingcheng奕  阅读(130)  评论(0编辑  收藏  举报