Foundations Working with digits and divisors

30. Palindrome Number

Easy

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

Output: true

Explanation: From right to left the digits are 7, 2, 4, 2, 7, the same as from left to right.

Example 2

Input: x = -505

Output: false

Explanation: From right to left it reads 505−. The minus sign has no partner at the other end.

Example 3

Input: x = 4500

Output: false

Explanation: 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.

x = 0

Constraints

  • -9 × 1015 ≤ x ≤ 9 × 1015

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.