
Problem
Solution
Submissions
Check if a Number is a Palindrome
Certification: Basic Level
Accuracy: 69.23%
Submissions: 13
Points: 10
Write a C++ function to check if a given integer is a palindrome. A palindrome number reads the same backward as forward.
Example 1
- Input: number = 121
- Output: true
- Explanation:
- Step 1: Read the number from right to left.
- Step 2: Compare with the original number.
- Step 3: Since both are the same, return true.
Example 2
- Input: number = 123
- Output: false
- Explanation:
- Step 1: Read the number from right to left, which gives 321.
- Step 2: Compare with the original number 123.
- Step 3: Since they are different, return false.
Constraints
- -2^31 ≤ number ≤ 2^31 - 1
- Time Complexity: O(n), where n is the number of digits in the number
- 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
- Convert the number to a string and compare it with its reverse.
- Use arithmetic operations to reverse the number and compare it with the original number.
- Handle negative numbers separately since they cannot be palindromes.