您的位置:首页 > 其它

【leetcode】 9. palindrome number

2015-07-13 09:53 381 查看
@requires_authorization
@author johnsondu
@create_time 2015.7.13 9:48
@url [palindrome-number](https://leetcode.com/problems/palindrome-number/)
/************************
*  分离出最左边和最右边的数
*  然后依次对比即可
***********************/
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
if(x < 10) return true;

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

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