> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/125.valid_palindrome.md).

# 125.Valid Palindrome

**125.Valid Palindrome**

> 给定一个字符串，验证它是否是回文串，只考虑字母和数字字符，可以忽略字母的大小写。 说明：本题中，我们将空字符串定义为有效的回文串。

```
示例 1:

输入: "A man, a plan, a canal: Panama"
输出: true
示例 2:

输入: "race a car"
输出: false
```

难度：Easy 方法:去除无关字符，大小写转换之后，再判断即可。 代码如下:

```
class Solution {
public:
    bool isPalindrome(string s) {
        int t=s.length();
        string tmp;
        for(int i=0;i<t;i++)
        {
            if(s[i]>64 && s[i]<91)
                tmp+=s[i]+32;
            else if(s[i]>96 && s[i]<123)
                tmp +=s[i];
            else if(s[i]>47 &&s[i]<58)
                tmp +=s[i];
        }
       // cout << tmp << endl;
        int n=tmp.length();
        for(int i=0;i<n/2;i++)
        {
            if(tmp[i]!=tmp[n-i-1]) return false;
        }
        return true;
    }
};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://dfine.gitbook.io/leetcode/125.valid_palindrome.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
