5-lines JAVA


  • 0
    P
        public int reverse(int x) {
            String temp = Long.toString(x < 0 ? -(long)x : (long)x);
            long res = Long.parseLong(new StringBuilder(temp).reverse().toString());
            if(res > Integer.MAX_VALUE)
                return 0;
            return x < 0 ? -(int)res : (int)res;
        }
    

Log in to reply
 

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