Reversing Integer in Java


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

Log in to reply
 

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