mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-29 00:33:14 +03:00
17 lines
310 B
C
17 lines
310 B
C
bool isPalindrome(int x)
|
|
{
|
|
if (x < 0 || (x % 10 == 0 && x != 0))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
int revertedNumber = 0;
|
|
while (x > revertedNumber)
|
|
{
|
|
revertedNumber = revertedNumber * 10 + x % 10;
|
|
x /= 10;
|
|
}
|
|
|
|
return x == revertedNumber || x == revertedNumber / 10;
|
|
}
|