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.
Restrições
-10¹⁸ ≤ n ≤ 10¹⁸
Exemplos
Entrada:
n = 12321
Saída esperada:
expected = True
Entrada:
long long n = 12321;
Saída esperada:
bool expected = true;
Entrada:
long n = 12321;
Saída esperada:
bool expected = true;
Explicação
12321 reversed is 12321.
Entrada:
n = -121
Saída esperada:
expected = False
Entrada:
long long n = -121;
Saída esperada:
bool expected = false;
Entrada:
long n = -121;
Saída esperada:
bool expected = false;
Explicação
The minus sign makes "-121" differ from "121-".
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
A negative number cannot be a palindrome because of the minus sign.
Dica 2
Compare the number’s digits from both ends rather than converting unnecessarily.
Dica 3
Single-digit numbers are always palindromes.
Complexidade esperada
O(log n) time, O(1) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.