Accepted 7 line Java solution


  • 0
    J
    public int reverse(int x) {
      long reverseNum = 0;
      while(x != 0) {
         reverseNum = reverseNum * 10 + x % 10;
          x /= 10;
          if(reverseNum > Integer.MAX_VALUE || reverseNum < Integer.MIN_VALUE) return 0;
      }
      return (int) reverseNum;
    }
    

Log in to reply
 

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