> 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/9.palindrome_number.md).

# 9.Palindrome Number

**9.Palindrome Number**

难度:Easy

> 判断一个整数是否是回文数。回文数是指正序（从左向右）和倒序（从右向左）读都是一样的整数。

```
示例 1:

输入: 121
输出: true
示例 2:

输入: -121
输出: false
解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
示例 3:

输入: 10
输出: false
解释: 从右向左读, 为 01 。因此它不是一个回文数。
```

进阶: 你能不将整数转为字符串来解决这个问题吗？

不适用字符串,就直接从前后开始判断位置上的数字是否相等,用直接相加求回文数会有溢出错误,所以用减的.

```
class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0 || x==10) return false;
        if(x<10) return true;
        int s=log10(x);
        while(s>0){
        int f=x/pow(10,s);
        int l=x%10;
        //cout<< f<<","<<l<<endl;
        if (f!=l) return false;
        x=(x-f*pow(10,s))/10;
        s-=2;

        }
        return true;
    }
};
```

> 执行用时 : 80 ms, 在Palindrome Number的C++提交中击败了72.04% 的用户 内存消耗 : 8.4 MB, 在Palindrome Number的C++提交中击败了78.54% 的用户


---

# 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/9.palindrome_number.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.
