
Problem
Solution
Submissions
Check if Number is Palindrome
Certification: Basic Level
Accuracy: 83.33%
Submissions: 6
Points: 5
Write a Java program to determine whether an integer is a palindrome. Do not convert the integer to a string — solve it mathematically.
Example 1
- Input: x = 121
- Output: true
- Explanation:
- Reverses to same value → it is a palindrome
Example 2
- Input: x = -121
- Output: false
- Explanation:
- Negative values are not palindromes
Constraints
- -2^31 ≤ x ≤ 2^31 - 1
- Do not convert to string
- Time Complexity: O(log n)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Negative numbers are not palindromes due to the minus sign.
- Reverse the integer by extracting digits from right to left.
- Be careful about integer overflow when reversing.
- Compare the reversed integer with the original.
- Handle edge cases like numbers ending with 0.