Palindrome Number

Easy Math & Geometry AI round

x is a whole number. It is a palindrome when its digits read the same from right to left as from left to right.

Return true when x is a palindrome and false when it is not. A negative number never is, as its minus sign has no partner at the other end.

Try to answer by working with the number's digits, without writing x out as a string.

Example 1

Input: x = 4554
Output: true

Read from right to left, 4554 is 4, 5, 5, 4: the same digits in the same order.

Example 2

Input: x = -77
Output: false

Example 3

Input: x = 1200
Output: false

Constraints

  • -2³¹ ≤ x ≤ 2³¹ - 1

Watch the explanation

More Math & Geometry

All Math & Geometry problems