public static bool IsPalindrome(int x)
{
if (x < 0)
{
return false;
}
if (x < 10)
{
return true;
}
int div = 1;
while (x / div >= 10)
{
div *= 10;
}
while(x != 0)
{
int leftDigit = x / div;
int rightDigit = x % 10;
if (rightDigit != leftDigit)
{
return false;
}
x = (x % div) / 10;
div /= 100;
}
return true;
}
No comments:
Post a Comment