首页 > 其他 > 详细

Leetcode: Reverse Integer

时间:2015-03-16 20:55:47      阅读:290      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    int reverse(int x) {
        int flag = 1;
        long long x1 = x;
        if(x1 < 0) {
            flag = -1;
            x1 = 0-x1;
        }
        int remaind;
        long long result=0;

        while(x1){
            remaind = x1%10;
            x1 = x1 /10;
            result = result*10 + remaind ;
        }
        if(flag > 0 && result > 2147483647) return 0;
        if(flag<0 && result > 2147483648) return 0;
        return flag < 0? -result:result;
    }
};

  注意溢出问题

Leetcode: Reverse Integer

原文:http://www.cnblogs.com/chdxiaoming/p/4342651.html

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