Solution in JavaScript


  • 0
    R
    /**
     * @param {number} x
     * @return {number}
     */
    var reverse = function(x) {
        const INT_MAX = 2147483647;
        const INT_MIN = -2147483647;
        var reversed = 0;
        
    
     while (x != 0) {
      reversed *= 10;
      reversed += x % 10;
      x -= x % 10;
      x /= 10;
     }
        
    if(reversed <= INT_MAX && reversed >= INT_MIN)
        return reversed;
    else
        return 0;
    };
    

Log in to reply
 

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