Solution in JavaScript


  • 0
    K

    'use strict';
    var reverse = function (baseNumber) {
    let resultNumber;
    resultNumber = String(baseNumber).split('').reverse().join('');
    if (resultNumber[0] === "0") {
    resultNumber = resultNumber.slice(1);
    }
    if (resultNumber[resultNumber.length-1] === "-") {
    resultNumber = -(resultNumber.slice(0,-1));
    }
    resultNumber = +resultNumber;
    if (resultNumber > 2147483648 || resultNumber < -2147483648 ) {
    return 0;
    }
    return resultNumber;
    };
    reverse(123);


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.