Solution by <abhileshpatil>


  • 0
    A

    Java

    class Solution {
        String xy="";
        public int reverse(int x) {
            try
      {
       if(x==0)
            {
                return (0);
            }
            if(x<0)
            {
                x=Math.abs(x);
                xy="-";
            }
            while(x!=0)
            {
                
                xy=xy+(x%10);
                x=x/10;
            }
            return (Integer.parseInt(xy));
      }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.