Java solution


  • 0
    R
    class Solution {
        public int reverse(int x) {
            int result = 0;
            
            while(x != 0) {
                if(result < -(Math.pow(2, 31) / 10) || result > Math.pow(2, 31) / 10)
                    return 0;
                result = result * 10 + (x % 10);
                x = x / 10;
            }
            return result;
        }
    }
    

Log in to reply
 

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