LeetCode_Palindrome Number

Description:检查输入的数据是否是回文数,如果是返回true,否则返回false
input:121
output:true

input:-121
output:false

input:10
output:false

ps:试着不要将int转换为string

bool isPalindrome(int x) {
	if (x < 0)
		return false;
	else {
		long long rec = 0;    //rec要保存最大的int回文后的数
		int x_cp = x;
		while (x_cp != 0) {
			rec = rec * 10 + x_cp % 10;
			x_cp /= 10;
		}
		if (rec == x)
			return true;
		else
			return false;
	}
}

猜你喜欢

转载自blog.csdn.net/lancelot0902/article/details/90747699