2 ms simple and easy JAVA solution


  • 0
    R
    public class Solution 
    {
        public int reverse(int x) 
        {
            int result = 0;
            while(x != 0)
            {
                int newResult = result*10 + x%10;
                if((newResult - x%10)/10 != result)
                    return 0; 
                x = x/10;
                result = newResult;
            }
            return result;
        }
    }

Log in to reply
 

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