LeetCode Palindrome Number

本文详细介绍了如何解决微策略面试中关于判断整数是否为回文数的问题,包括代码实现和核心思路解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这题上次回家微策略的电面题,也是当时写代码,当时思路混乱没立刻写出来,后来好像说了说想法,想法是对的。忘了是不是当初死在这题上了,现在都无所谓了。

#include "stdafx.h"
#include <iostream>
using namespace std;

bool isPalindrome(int x) {
	if (x<0)
	{
		return false;
	}
	int highbit=1;
	int temp = x;
	temp = temp/10;
	if (temp==0)
	{
		return true;
	}
	while(temp!=0)
	{
		highbit*=10;
		temp/=10;
	}
	const int lowbit=10;
	while(highbit>=lowbit)
	{
		if (x/highbit!=x%lowbit)
		{
			return false;
		}
		x%=highbit;//delete the highest bit
		x/=lowbit;//delete the lowest bit
		highbit/=100;
	}
	return true;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int a;
	while(cin>>a)
	{
		cout<<isPalindrome(a)<<endl;
	}
	system("pause");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值