Foundations Working with digits and divisors
30. Palindrome Number
Given an integer x, return true if x is a palindrome, and false otherwise.
A number is a palindrome when its digits read the same from right to left as from left to right. So 383 and 7 are palindromes, and 380 is not.
A negative number is written with a minus sign in front. Read from right to left, −383 becomes 383−, so a negative number is never a palindrome.
Example 1
Input: x = 72427
trueExplanation: From right to left the digits are 7, 2, 4, 2, 7, the same as from left to right.
Example 2
Input: x = -505
falseExplanation: From right to left it reads 505−. The minus sign has no partner at the other end.
Example 3
Input: x = 4500
falseExplanation: From right to left it reads 0054, which is not 4500.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
-9 × 1015 ≤ x ≤ 9 × 1015
Clarifying questions
What you would ask an interviewer before writing any code.