Problema
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.
Restricciones
-10¹⁸ ≤ n ≤ 10¹⁸
Ejemplos
Entrada:
n = 12321
Salida esperada:
expected = True
Entrada:
long long n = 12321;
Salida esperada:
bool expected = true;
Entrada:
long n = 12321;
Salida esperada:
bool expected = true;
Explicación
12321 reversed is 12321.
Entrada:
n = -121
Salida esperada:
expected = False
Entrada:
long long n = -121;
Salida esperada:
bool expected = false;
Entrada:
long n = -121;
Salida esperada:
bool expected = false;
Explicación
The minus sign makes "-121" differ from "121-".
Cómo abordarlo
Inténtalo primero por tu cuenta y luego abre las pistas una a una.
Pista 1
A negative number cannot be a palindrome because of the minus sign.
Pista 2
Compare the number’s digits from both ends rather than converting unnecessarily.
Pista 3
Single-digit numbers are always palindromes.
Complejidad esperada
O(log n) time, O(1) extra space
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.