solution in java


  • 0
    V
            boolean flag = false;
    
            if (x < 0) {
                x = 0 - x;
                flag = true;
            }
    
            while (x > 0) {
                int rem = x % 10;
                sum = sum * 10 + rem;
                x = x / 10;
            }
            if (sum > Integer.MAX_VALUE) {
                return 0;
            }
            return flag == true ? -(int) sum : (int) sum; 
    

Log in to reply
 

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