【LeetCode】【esay】【07】整数反转

var common = function(x){

    let cntN = (x + '').length;
    let rs = 0;

    for(let i = (cntN-1),j=0 ; i >-1;i--,j++){

        let temp = Math.floor(x/Math.pow(10,i));
        x = x - temp*Math.pow(10,i);
        rs += temp*Math.pow(10,j);
    }

    return rs;
}

/**
 * @param {number} x
 * @return {number}
 */
var reverse = function(x) {

    if(x>0&&x<1534236469){
        return common(x);
    }else if(x==0||x==(-1563847412)||x>1534236468||((-x)>2147483412)){
        return 0;
    }else{
        return -common(-x); 
    }
};

整数溢出 我还得查查~~!!!

猜你喜欢

转载自blog.csdn.net/MENGCHIXIANZI/article/details/106177013