Please check the test cases in the case of java script.


  • 0
    K

    /**

    • @param {number} x

    • @return {number}
      /
      var reverse = function(x) {
      var num = 0,isNegative=0,prev=0;
      if(x<0) {
      x=x
      -1;
      isNegative=1;
      }
      while(x>0) {
      var rem = x%10;
      num = 10*num+rem;
      var prev = x;
      x/=10;
      x = parseInt(x);
      //console.log(x,num,rem)
      if(x != (prev-rem)/10) {
      num=0;
      break;
      }
      }
      if(isNegative) {
      num = num *-1;
      }

      return num;
      };


Log in to reply
 

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