leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

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

Open riveridea opened this issue 10 years ago • 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;

riveridea avatar Jan 14 '15 00:01 riveridea