just 6ms in C and easy check for overflow


  • 1
    W

    int reverse(int x)
    {
    long int temp=0;
    while(fabs(x)>0)
    {
    temp=temp*10+x%10;
    x/=10;
    }
    if ( temp > INT_MAX || temp < (-INT_MAX - 1) )
    return 0;
    else
    return temp;

    }


Log in to reply
 

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