Reverse Integer in Java


  • 0
    G
    class Solution {
        public int reverse(int x) {
            int rev = 0;
            while (x!=0) {
                rev = rev*10 + x%10;
                x = x/10;
            }
            return rev;
        }
    }
    

Log in to reply
 

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