Solution in JS


  • 0
    H

    const INT_MAX = 2147483647
    const INT_MIN = -2147483647
    var reverse = function(number) {
    const isNegative = number < 0
    number = Math.abs(number)
    if (number < 10) {
    return number
    }

    var temp = 0

    while (number >= 10) {
    mod = number % 10
    number = (number - mod) / 10
    temp = temp * 10 + mod
    }

    temp = temp * 10 + number
    if (isNegative) temp = -1 * temp

    if (temp > INT_MAX || temp < INT_MIN) return 0

    return temp
    }


Log in to reply
 

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