leetcoede新题Valid Palindrome# JobHunting - 待字闺中
l*a
1 楼
大case有4个过不去,看不出倪端。
bool isPalindrome(string A) {
int i = 0; int j = A.length() - 1;
while(i < j){
while(i < A.length() && !(('a' <= A[i] && A[i] <= 'z') || ('A' <
= A[i] && A[i] <= 'z') || ('1' <= A[i] && A[i] <= '9'))){
i++;
}
while(j >= 0 && !(('a' <= A[j] && A[j] <= 'z') || ('A' <= A[j] &
& A[j] <= 'z') || ('1' <= A[j] && A[j] <= '9'))){
j--;
}
if(i >= j) return true;
if(tolower(A[i]) != tolower(A[j])){
return false;
}else{
i++;
j--;
}
}
return i >= j;
}
bool isPalindrome(string A) {
int i = 0; int j = A.length() - 1;
while(i < j){
while(i < A.length() && !(('a' <= A[i] && A[i] <= 'z') || ('A' <
= A[i] && A[i] <= 'z') || ('1' <= A[i] && A[i] <= '9'))){
i++;
}
while(j >= 0 && !(('a' <= A[j] && A[j] <= 'z') || ('A' <= A[j] &
& A[j] <= 'z') || ('1' <= A[j] && A[j] <= '9'))){
j--;
}
if(i >= j) return true;
if(tolower(A[i]) != tolower(A[j])){
return false;
}else{
i++;
j--;
}
}
return i >= j;
}