【LeetCode125】Valid Palindrome

class Solution {
public:
    bool isPalindrome(string s) {
        if(s == "")
                return true;
        for(int l = 0, r = s.length()-1; l < r; l++, r--){  //多个条件
            while(!isalnum(s[l]) && l < r)  //isalnum函数第一次见,同时需要考虑为了躲开无效字符是否越界
                l++;
            while(!isalnum(s[r]) && l < r)
                r--;
            if(toupper(s[l]) != toupper(s[r])) return false;  //toupper函数第一次见
        }
        return true;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_39458342/article/details/88051452
今日推荐