simple java solution


  • 1
    F

    sorry for bad english

    public int reverse(int x) {
            int result = 0, temp = 0;
            while (Math.abs(x) > 0) {
                result = result * 10 + x % 10;
                if (result / 10 != temp) {
                    return 0;
                }
                temp = result;
                x /= 10;
            }
            return result;
        }
    

Log in to reply
 

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