双指针验证回文串

class Solution {
public:
    bool isPalindrome(string s) {
        string sgood;
        for (char ch: s) {
            if (isalnum(ch)) {  //判断是否是数字或者字母
                sgood += tolower(ch);    //tolower 将大写转化为小写  ,这两个注意头文件<cctype>
            }
        }
        int n = sgood.size();
        int left = 0, right = n - 1;
        while (left < right) {
           if (sgood[left] != sgood[right]) {
                return false;
            }
            ++left;
            --right;
        }
        return true;
    }
};
posted @ 2021-03-28 16:54  jakekiller00  阅读(47)  评论(0编辑  收藏  举报