Reverse Integer


  • 0
    I

    MY JAVA APPROACH

     public int reverse(int x) {
    		try{
    			if(x<0)
    			    return Integer.parseInt("-"+new StringBuilder(String.valueOf(x).substring(1)).reverse().toString()); 
    			    return Integer.parseInt(new StringBuilder(String.valueOf(x)).reverse().toString());
    		}catch(Exception e){
    			return 0;
    		}
        }
    
    
    
    

Log in to reply
 

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