# LeetCode 125. Valid Palindrome

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

**Example 1:**

```
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
```

**Example 2:**

```
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
```

**Constraints:**

* `1 <= s.length <= 2 * 105`
* `s` consists only of printable ASCII characters.

## Solution

[English Version in Youtube](https://youtu.be/TczseY1HaXI)

[中文版解答Youtube Link](https://youtu.be/4o2yZy_-iV0)

[中文版解答Bilibili Link](https://www.bilibili.com/video/BV1TK4y1o7aa/)

```
class Solution {

public:
    bool isPalindrome(string s) {
        int i = 0, j = s.length() - 1;
        while (i < j) {
            while (!isalpha(s[i]) && !isdigit(s[i]) && i <= j) {
                i++;
            }
            while (!isalpha(s[j]) && !isdigit(s[j]) && i <= j) {
                j--;
            }
            if (i >= j) {
                break;
            }
            if (toupper(s[i]) != toupper(s[j])) {
                return false;
            }
            
            i++;
            j--;
        }
        
        return true;
    }
    
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zhenchaogan.gitbook.io/leetcode-solution/leetcode-125-valid-palindrome.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
