Solution in Java


  • 0
    F
    public class Solution {
        public int reverse(int x) {
            long result = 0;
            int tmp = Math.abs(x);
            while(tmp>0){
                result = result * 10;
                result = result + tmp%10;
                if(result>Integer.MAX_VALUE) {
                    return 0;
                }
                tmp = tmp/10;
            }
            return (int)(x>0?result:-result);
        }
    }
    

Log in to reply
 

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