Menu
CoddyTech

Palindrome Number

A number is a palindrome when its digits read the same from left to right and from right to left, like 1221. Given an integer x, return true if it is a palindrome and false otherwise. A negative number never counts, because its minus sign has no partner at the other end.

Function

isPalindrome(x: integer) → boolean
xinteger
the integer to check, possibly negative
Returnsboolean
true if x reads the same in both directions, false otherwise

Constraints

  • -231 ≤ x ≤ 231-1
  • Every negative number returns false.

Examples

Input
x = 121
Output
true
Explanation
Read backwards, 121 is still 121, so the answer is true.
challenge icon

Follow-up

Can you solve it without converting the integer to a string?

Reset code
def isPalindrome(x):
    # Write code here

Test #1

Test #2

Argument

x = 121

Expected Output

true