JAVA-----------Easy Version To Understand!!!!!!!!


  • 0
    H
    	public static int reverse(int x) {
    	if (x == 0)
    		return 0;
    	int sign = 1;
    	if (x < 0)
    		sign = -1;
    	long number = Math.abs((long) x), sum = 0;
    	while (number != 0) {
    		sum = sum * 10 + number % 10;
    		number = number / 10;
    	}
    
    	if (sign * sum > Integer.MAX_VALUE || sign * sum < Integer.MIN_VALUE)
    		return 0;
    	return sign * (int) sum;
    }

  • 0
    D

    No need to store the sign. The % and / operations don't change the sign of the input.


  • 0
    F

    cant agree with u


Log in to reply
 

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