Question: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome. 

```
class Solution {
public:
    bool isPalindrome(string s) {
        if (!s.length()) return true;
        int i = 0, j = s.length() - 1;
        for (int k = 0; k < j; ++k)
            s[k] = tolower(s[k]);
        while (i < j) {
            if ((s[i] < 48)||(s[i] > 57 && s[i] < 97)||(s[i] > 122))
                ++i;
            else if ((s[j] < 48)||(s[j] > 57 && s[j] < 97)||(s[j] > 122))
                --j;
            else if (s[i++] != s[j--]) return false;
        }
        return true;
    }
};

```

```
Wrong answer：
Input:  "!bHvX!?!!vHbX" 
Output:   true 
Expected:  false
```

What's wrong with it?

Answer: 
You never convert the last character to lower case because the loop condition is k < j and j is the index of the last character. Change the loop to:

```
for (int k = 0; k <= j; ++k)
    s[k] = tolower(s[k]);

```

Also, the code would be a easier to read if you used character constants such as `'a'` instead of ASCII codes.
You may iterate through the string in both directions until the pointers meet. It will be something like this:

```
bool isPalindrome(std::string const& s) {
    int len = s.length();
    int i = 0;
    int j = len - 1;
    while (true) {
        // Skip garbage characters.
        while (i < len && !isalpha(s[i])) ++i;
        while (j >= 0  && !isalpha(s[j])) --j;

        if (i < j && tolower(s[i]) == tolower(s[j]))
            continue;

        if (i >= j)
            return true;

        return false;
    }

```

Note here `len` is a signed variable, despite `s.length()` is `size_t`.