[LintCode] Reverse Integer

public int reverseInteger(int n) {
        // Write your code here
        int num = Math.abs(n);
        int res = 0;
        while(num != 0) {
            if(res > (Integer.MAX_VALUE - num%10) / 10)
                return 0; // corn case;
            res = res*10 + num %10;
            num /= 10;
        }
        return n > 0 ? res : -res;
    }