# 125. Valid Palindrome

[Link](https://leetcode.com/problems/valid-palindrome/)

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

**Note:** For the purpose of this problem, we define empty string as valid palindrome.

**Example 1:**

```
Input: "A man, a plan, a canal: Panama"
Output: true
```

**Example 2:**

```
Input: "race a car"
Output: false
```

**Solution**

```
    public boolean isPalindrome(String s) {
        int headIndex = 0, tailIndex = s.length()-1;
        
        while(headIndex <= tailIndex){
            char chead = s.charAt(headIndex);
            char ctail = s.charAt(tailIndex);
            //Remeber Character.isLetterOrDigit(c)
            if(!Character.isLetterOrDigit(chead)){
                headIndex++;
            }else if (!Character.isLetterOrDigit(ctail)){
                tailIndex--;
            }else{
                //Remeber Character.toLowerCase(c)
                if(Character.toLowerCase(chead) != Character.toLowerCase(ctail)){
                    return false;
                }
                headIndex++;
                tailIndex--;
            }
        }
        return true;
    }
```
