Problem
Decide whether the decimal digits of n read the same forwards and backwards. Negative numbers are never palindromes because of the minus sign.
Implement is_palindrome_number(n).
Input
n: The number to check.
Output
Return true for a palindromic number, otherwise false.
Constraints
-10¹⁸ ≤ n ≤ 10¹⁸
Examples
Input:
n = 12321
Expected output:
expected = True
Input:
long long n = 12321;
Expected output:
bool expected = true;
Input:
long n = 12321;
Expected output:
bool expected = true;
Explanation
12321 reversed is 12321.
Input:
n = -121
Expected output:
expected = False
Input:
long long n = -121;
Expected output:
bool expected = false;
Input:
long n = -121;
Expected output:
bool expected = false;
Explanation
The minus sign makes "-121" differ from "121-".
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
A negative number cannot be a palindrome because of the minus sign.
Hint 2
Compare the number’s digits from both ends rather than converting unnecessarily.
Hint 3
Single-digit numbers are always palindromes.
Expected complexity
O(log n) time, O(1) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.