C code


  • 0
    J

    int reverse(int x) {
    int sign = (x>0) ? 1 : -1;
    long result = 0;
    int absolute_input = sign*x;

    while(absolute_input>0) {
        result = result*10 + absolute_input % 10;
        absolute_input = absolute_input/10;        
    }
    if (result>2147483647) return 0;
    
    return (int) result*sign;
    

    }


Log in to reply
 

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