Palindrome Number(回文整数)

Determine whether an integer is a palindrome. Do this without extra space.
解析:把该整数倒转过来,如果和原来的数字相等,则说明是回文整数。注意:任何负数都不是回文整数。
bool isPalindrome(int x)
{
	if (x < 0)
		return false;
	int res = 0;
	int val = x;
	while (val)
	{
		res = res * 10 + val % 10;
		val /= 10;
	}
	if (res == x)
		return true;
	else
		return false;
}

你可能感兴趣的:(Palindrome Number(回文整数))