class Solution {
public:
bool isPalindrome(string s) {
int len = s.length();
if(len == 0){
return true;
}
int left = 0, right = len - 1;
for(int i = 0; i < len; ++i){
if(s[i] >= 'A' && s[i] <= 'Z'){
int bias = s[i] - 'A';
s[i] = 'a' + bias;
}
}
while(left < right){
while(left < right && !((s[left] >= 'a' && s[right] <= 'z') || (s[left] >= '0' && s[left] <= '9'))){
++left;
}
if(left >= right){
return true;
}
while(right > left && !((s[right] >= 'a' && s[right] <= 'z') || (s[right] >= '0' && s[right] <= '9'))){
--right;
}
if(left >= right){
return true;
}
if(s[left] != s[right]){
return false;
}
++left;
--right;
}
return true;
}
};
错误1:
alphanumeric的判断:
(s[i] >= ‘a’ && s[i] <= ‘z’) || (s[i] >= ‘A’ && s[i] <= ‘Z’) || (s[i] >= ‘0’ && s[i] <= ‘9’)
错误2:
‘A’和’a’被认为是同一个数字…