欢迎使用CSDN-markdown编辑器

时间:2015-07-13 10:16:42   收藏:0   阅读:221
@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;
    }
};

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文:http://blog.csdn.net/zone_programming/article/details/46858727

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!