首页 > 其他 > 详细

7. Reverse Integer

时间:2019-02-14 21:12:57      阅读:155      评论:0      收藏:0      [点我收藏+]

7. Reverse Integer

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

Input: 123
Output: 321

Example 2:

Input: -123
Output: -321

Example 3:

Input: 120
Output: 21
题意:将int型的整数翻转输出
代码如下(js):
var reverse = function(x) {
    var res=0;
    while(x!=0){
        //取余
        res=res*10 + x%10;
     
        //减余除10
        x=(x-x%10)/10;
        // console.log(res,x)
    }
    
       //判断是否越界
    if(Math.pow(2,31)<res || Math.pow(2,31)<-res) return 0;
    // console.log(res);
    return res;
};

 

7. Reverse Integer

原文:https://www.cnblogs.com/xingguozhiming/p/10380615.html

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