首页 > 其他 > 详细

Palindrome Number

时间:2015-08-16 12:11:18      阅读:151      评论:0      收藏:0      [点我收藏+]

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

思路:将原数字从各位数字开始拆分成两部分,最终比较两个数字的大小即可。

public boolean isPalindromeII(int x) {
        if(x < 0 || x > 0 && x % 10 == 0) return false;
        int y = 0;
        while(x > y) {
            y = y * 10 + x % 10;
            x = x /10;
        }
        return x == y || x == y/10;
    }

 

Palindrome Number

原文:http://www.cnblogs.com/ivanyangzhi/p/4733959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!