标签:++ string https int code size pre ret false
时间复杂度:\(O(logn)\)
class Solution {
public:
bool isalpha(char c) {
if ((c >= ‘a‘ && c <= ‘z‘) || (c >= ‘A‘ && c <= ‘Z‘)) return true;
else return false;
}
bool isdigit(int c) {
if (c >= ‘0‘ && c <= ‘9‘) return true;
else return false;
}
bool isPalindrome(string s) {
if (s == "") return true;
int i = 0, j = s.size() - 1;
while (i < j) {
if (!isalpha(s[i]) && !isdigit(s[i])) {
i++;
continue;
}
if (!isalpha(s[j]) && !isdigit(s[j])) {
j--;
continue;
}
if (toupper(s[i]) != toupper(s[j])) return false;
i++, j--;
}
return true;
}
};
标签:++ string https int code size pre ret false
原文地址:https://www.cnblogs.com/clown9804/p/12552158.html