Whe dividend=2147483647 the result is " Time Limit Exceeded"?


  • -1
    S

    int divide(int dividend, int divisor) {
    if (!divisor || (dividend == INT_MIN && divisor == -1))
    return INT_MAX ;
    int tmpdividend,tmpdivisor;
    tmpdividend=abs(dividend);
    tmpdivisor=abs(divisor);
    int result,temp;
    result=temp=0;
    if(tmpdividend<tmpdivisor)
    return 0;
    while(tmpdividend>temp)
    {
    temp+=tmpdivisor;
    result++;
    }
    if(temp>tmpdividend)
    result--;
    if(dividend>0&&divisor<0||dividend<0&&divisor>0)
    result*=-1;
    return result;
    }


Log in to reply
 

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