您的位置:首页 > 其它

Palindrome Number(回文数字)

2015-03-27 09:38 176 查看

Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

每次对比最高位和最低位

bool isPalindrome(int x) {
if(x < 0) return false;
int base = 1;
while(x/base >= 10) base = base*10;
while(x){
int leftdigit = x/base;
int rightdigit = x%10;
if(leftdigit != rightdigit)
return false;
x -= leftdigit*base;
x = x/10;
base = base/100;
}
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: