首页 > 其他 > 详细

[leetcode]Palindrome Number

时间:2014-12-04 20:03:32      阅读:275      评论:0      收藏:0      [点我收藏+]

问题描述:

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

基本思路:

考虑到回文的特点,根据给定数字获得与给定数字低位高位反序的数字。如果是回文数,则两数想等;否则不等。(即使反序数字溢出,也可的到正确结果)

代码:

bool isPalindrome(int x) {  //C++
        int test = 0;
        int tmp = x;
        while(tmp>0 )
        {
            test = test*10+tmp%10;
            tmp = tmp/10;
        }
        return (test==x);
    }


[leetcode]Palindrome Number

原文:http://blog.csdn.net/chenlei0630/article/details/41727807

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