12 Lines simple Java Solution with 43ms runtime


  • 0
    A

    Accepted Java Solution with 12 lines of code and 43 ms runtime

        public int reverse(int n) {
        	long rev = 0;
    	while(n!=0){
    	    int r = n % 10;
                rev = (long)rev * 10 + r;
    	    n = n/10;
    	}
            if(rev > Integer.MAX_VALUE ||  rev < Integer.MIN_VALUE)
    	    return 0;
            else
    	    return (int)rev;
        }
    
    

Log in to reply
 

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