Palindrome Number - Problem

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

A palindrome number reads the same forward and backward. For example, 121 is a palindrome while 123 is not.

Follow up: Could you solve it without converting the integer to a string?

Input & Output

Example 1 — Positive Palindrome
$ Input: x = 121
Output: true
💡 Note: 121 reads the same from left to right and right to left
Example 2 — Not a Palindrome
$ Input: x = -121
Output: false
💡 Note: From left to right it reads -121, but from right to left it becomes 121- which is different
Example 3 — Single Digit
$ Input: x = 7
Output: true
💡 Note: Single digit numbers are always palindromes

Constraints

  • -231 ≤ x ≤ 231 - 1

Visualization

Tap to expand
Palindrome Number: Check if 121 reads same forwards and backwardsInput121Check1-2-1 vs 1-2-1Outputtrue121FirstLastMiddleFirst = Last (1 = 1) ✓ → Palindrome!
Understanding the Visualization
1
Input
Given integer x = 121
2
Process
Check if digits are symmetric
3
Output
Return true if palindrome, false otherwise
Key Takeaway
🎯 Key Insight: We only need to reverse half the number to check if it matches the other half
Asked in
Amazon 15 Microsoft 12 Google 8 Apple 6
329.6K Views
High Frequency
~15 min Avg. Time
8.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen