Reverse Integer


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

Log in to reply
 

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