Solution in Java


  • 0
    1

    class Solution {
    public int reverse(int n) {

    	int flag=1;
    	if(n<0)
    		flag=-1;
    	n=n*flag;
    	long res=0;
    	while(n>0)
    	{
    		res=res*10+n%10;
    		n/=10;
    	}
    	long a=res*flag;
    	 if(a<=Integer.MIN_VALUE || a>=Integer.MAX_VALUE)
                return 0;
    	return (int)a;
    }
    

    }


Log in to reply
 

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