题解 | #反转数字#

反转数字

http://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a

class Solution {
public:
    /**
     * 
     * @param x int整型 
     * @return int整型
     */
    #define MAX_value 2147483647
    #define MIN_value -2147483648
    int reverse(int x) {
        // write code here
        long y=0;//存放翻转之后的数据(用int类型的会出错)
        long x1=x;
        while(x1!=0)
        {
            y=y*10+x1%10;
            x1=x1/10;
        }
        if(y> MAX_value|| y< MIN_value)
            return 0;
        return (int)y;
    }
};
牛客刷题记录 文章被收录于专栏

记录自己的刷题记录,刷过的题的解法

全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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