Valid Palindrome(C++验证回文串)

解题思路:夹逼定理

class Solution {
public:
    bool isPalindrome(string s) {
        if (s.length()==0) return true;
        int i=0,j=s.length()-1;
        while(i<=j) {
            if(isalnum(s[i])) {
            	if(isalnum(s[j])) {
            		if (tolower(s[i])==tolower(s[j])) {
            			i++;
            			j--;
					} else return false;
				} else {
					j--;
				}
			} else {
				i++;
			} 
        }
        return true;
    }
};
发布了264 篇原创文章 · 获赞 272 · 访问量 42万+

猜你喜欢

转载自blog.csdn.net/coolsunxu/article/details/105519934