Skip to main content
Back to problems
Leetcode
Easy
Math
Strings
Two Pointers
Palindrome Number

Determine whether an integer reads the same forward and backward without converting it to a string if possible.

Acceptance 0%
Problem Statement

Problem

Given an integer x, return true if x is a palindrome, and false otherwise.

An integer is a palindrome when it reads the same from left to right and from right to left.

You should be careful about negative numbers and numbers ending in 0.

Goal

Write a function that checks whether the decimal representation of x is symmetric.

Input Format

  • A single integer x.

Output Format

  • Return true if x is a palindrome, otherwise return false.

Constraints

  • 231x2311-2^{31} \le x \le 2^{31} - 1
  • The answer should be based on the base-10 representation of the integer.
Examples
Sample cases returned by the problem API.

Example 1

Input

x = 121

Output

true

Explanation

The number reads the same forward and backward.

Example 2

Input

x = -121

Output

false

Explanation

From left to right it is -121, but from right to left it would be 121-.

Show 1 more example

Example 3

Input

x = 10

Output

false

Explanation

The reversed form would be 01, which is not the same as 10.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.