@@ -0,0 +1,914 @@
+package leetcode1_10;%0A%0A/**Reverse digits of an integer.%0A Example1: x = 123, return 321%0A Example2: x = -123, return -321%0A * Created by eugene on 16/4/20.%0A */%0Apublic class ReverseInteger %7B%0A%0A    //%E7%A9%BA%E9%97%B4O(1)%0A    public int reverse(int x) %7B%0A        long rev = 0;%0A        while(x!= 0)%7B%0A            rev = rev*10 + x%2510;%0A            x = x/10;%0A            if( rev%3EInteger.MAX_VALUE %7C%7C rev%3CInteger.MIN_VALUE)%0A                return 0;%0A        %7D%0A        return (int)rev;%0A    %7D%0A%0A    //%E7%A9%BA%E9%97%B4O(n)%0A    public int reverse1(int x) %7B%0A        if (x==0 %7C%7C x==Integer.MIN_VALUE) return 0; //TODO Integer.MIN_VALUE%E6%97%B6%E4%B9%9F%E8%BF%94%E5%9B%9E0%0A        int n = x;%0A        if (x%3C0) n = -n;%0A        StringBuilder s = new StringBuilder(String.valueOf(n)).reverse();%0A        int i = 0;%0A        while (s.charAt(i)=='0') i++;%0A        long l = Long.valueOf(s.substring(i));%0A        if (l%3EInteger.MAX_VALUE) return 0;%0A        if (x%3C0) l = -l;%0A        return (int)l;%0A    %7D%0A%0A%7D%0A

Reverse Integer