soulmachine/leetcode

15.13 divide two integers, need to retrun INT_MAX when result is overflow

riveridea opened this issue · 0 comments

Leetcode has added the new case for this problem, when overflow occurs, need to return INT_MAX, the current code can NOT be accepted. I adjust the return code as this and accepted.

    long long ret =    ((dividend^divisor) >> 31)?(-multi): multi;

    if (ret > INT_MAX)
        return INT_MAX;
    else
        return ret;