首页 > 其他 > 详细

LeetCode--Reverse Integer

时间:2015-01-08 09:42:55      阅读:293      评论:0      收藏:0      [点我收藏+]

Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

class Solution 
{
public:
    int reverse(int x) 
    {
        if(x>2147483647 || x <= -2147483648 || x == 0  )
            return 0;
        if(x < 0 )
            return (-reverse(-x));
        vector<int> temp;
        while(x > 0)
        {
            temp.push_back(x%10);
            x = x/10;
        }
        long long res = 0;
        for(int i=0; i<temp.size(); i++)
            res = res*10+temp[i];
        if(res>2147483647)
            return 0;
        return res;
    }
};


LeetCode--Reverse Integer

原文:http://blog.csdn.net/shaya118/article/details/42507369

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