My Simple Java Solution


  • 1
    L
    public int reverse(int x) {
            long ret=0;
            long z=ret;
            while(x!=0)
            {
                ret=x%10+ret*10;
                z=ret;
                x=x/10;
            }
            if((ret>Integer.MAX_VALUE||ret<Integer.MIN_VALUE))
                return 0;
            return (int)ret;
        }

  • 0
    L

    why do you need z=ret? I think it works without this line too.


Log in to reply
 

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