2019-07-21刷题-3

2019-07-22  本文已影响0人  nowherespyfly

题目序号:1,167,125

class Solution {
public:
    bool isPalindrome(string s) {
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        // cout << s << endl;
        int str_size = s.size();
        int i = 0, j = str_size;
        bool FLAG = true;
        while(i < j){
            while((i<str_size) && !isalpha(s[i]) && !isdigit(s[i]))
                i++;
            // cout << "here";
            while((j>=0) && !isalpha(s[j]) && !isdigit(s[j]))
                j--;
            // cout << "here";
            if(i >= j)
                break;
            if(s[i] != s[j]){
                cout << s[i] << " " << s[j] << endl;
                FLAG = false;
                break;
            }
            i++;
            j--;
        }
        return FLAG;
    }
};
上一篇下一篇

猜你喜欢

热点阅读