LeetCode 7. Reverse Integer

贼坑的一道题;可能太久没写题目了,第一道就错了无数次

code:
class Solution {
    public: 
        int reverse(int x) {
            int y=0,tt=1;
            if(x<0&&(x+INT_MAX)<0) return 0;
            if(x<0) tt=-1,x*=-1;
            while(x)
            {
                if((tt>0&&y>(INT_MAX-x%10*tt)/10)||(tt<0&&y<(INT_MIN-x%10*tt)/10)) return 0;
                y=y*10+x%10*tt;
                x/=10;
            }
            return y;
        }
};



全部评论

相关推荐

千千倩倩:简历问题有点多,加v细聊
点赞 评论 收藏
分享
notbeentak...:孩子,说实话,选择很重要,可能你换一个方向会好很多,但是现在时间不太够了,除非准备春招
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务