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

# Problem 9: Palindrome Number

> <https://leetcode.com/problems/palindrome-number/>

## 思路

![](/files/-Lpv9zSYkjB4p5ug_NKL)

```java
public class Solution {
    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }

        int div = 1;
        while (x / div >= 10) {
            div *= 10;
        }
        while (x != 0) {
            int left = x / div; // get highest pos;
            int right = x % 10; // git lowest pos;
            if (left != right) {
                return false;
            }

            x = (x % div) / 10;
            div = div / 100;
        }

        return true;
    }
}
```

## 易错点

1. 去掉头再去掉尾

   ```java
   x = (x % div) / 10; // x % div 去掉了头，除以10　去掉尾
   ```

   ２. div 除以 100，因为 ｘ 去掉了两位　


---

# 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:

```
GET https://liuyang89116.gitbook.io/my-leetcode-book/post_chapter_2_math/problem_9_palindrome_number.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.
