码迷,mamicode.com
首页 > 其他好文 > 详细

leetcde 9 Palindrome Number

时间:2017-02-01 21:42:20      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:remove   isp   ati   bool   ret   and   lin   tail   als   

class Solution {
public:
bool isPalindrome(int x) {

//negative number
if(x < 0)
return false;

int len = 1;
while(x / len >= 10)
len *= 10;

while(x > 0) {

//get the head and tail number
int left = x / len;
int right = x % 10;

if(left != right)
return false;
else {
//remove the head and tail number
x = (x % len) / 10;
len /= 100;
}
}

return true;
}
};

leetcde 9 Palindrome Number

标签:remove   isp   ati   bool   ret   and   lin   tail   als   

原文地址:http://www.cnblogs.com/wangkun1993/p/6360352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!