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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code