# LeetCode Valid Palindrome

LeetCode Valid Palindrome

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.

Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.

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

```bool isAlphaNum(char c) {
return (c >= 'A'&&c <= 'Z') || (c >= 'a'&&c <= 'z') || (c >= '0'&&c <= '9');
}
char upper2lower(char c) {
if (c >= 'A'&&c <= 'Z')return c + 32;
return c;
}
class Solution {
public:
bool isPalindrome(string s) {
int i = 0, j = s.size() - 1;
while (i < s.size() && j >= 0) {
while (!isAlphaNum(s[i]) && i < s.size())i++;
if (i >= s.size())break;
char c1 = upper2lower(s[i]);
while (!isAlphaNum(s[j]) && j >= 0)j--;
if (j < 0)break;
char c2 = upper2lower(s[j]);
if (c1 != c2)return false;
i++;
j--;
}
return true;
}
};
```

```bool isAlphaNum(char c) {
return (c >= 'A'&&c <= 'Z') || (c >= 'a'&&c <= 'z') || (c >= '0'&&c <= '9');
}
char upper2lower(char c) {
if (c >= 'A'&&c <= 'Z')return c + 32;
return c;
}
class Solution {
public:
bool isPalindrome(string s) {
int i = 0, j = s.size() - 1;
while (i <= j) {
while (!isAlphaNum(s[i]) && i <= j)i++;
if (i > j)break;
char c1 = upper2lower(s[i]);
while (!isAlphaNum(s[j]) && i <= j)j--;
if (i > j)break;
char c2 = upper2lower(s[j]);
if (c1 != c2)return false;
i++;
j--;
}
return true;
}
};
```