leetcode-----125. 验证回文串

代码

/*
 * @lc app=leetcode.cn id=125 lang=cpp
 *
 * [125] 验证回文串
 */

// @lc code=start
class Solution {
public:
    bool check(char c) {
        return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >='0' && c <= '9';
    }
    
    bool isPalindrome(string s) {
        for (int i = 0, j = s.size() - 1; i < j; ++i, --j) {
            while (i < j && !check(s[i])) ++i;
            while (i < j && !check(s[j])) --j;
            if (i < j && tolower(s[i]) != tolower(s[j])) return false;
        }
        return true;
    }
};
// @lc code=end


猜你喜欢

转载自www.cnblogs.com/clown9804/p/13399759.html