class Solution {
public:
    int divide(int dividend, int divisor) {
        if(dividend == INT_MIN && divisor == -1) return INT_MAX;
        
        long long A = llabs(dividend),B = llabs(divisor),ans = 0;
        while(A >= B)
        {
            long long base = B,m = 1;
            while(base << 1 <= A)
            {
                base <<= 1;
                m <<= 1;
            }
            ans += m;
            A -= base;
        }
        return (dividend > 0) ^ (divisor > 0) ? -ans:ans;
    }
};

运行效率:

Runtime: 4 ms, faster than 52.14% of C++ online submissions for Divide Two Integers.
Memory Usage: 5.9 MB, less than 72.24% of C++ online submissions for Divide Two Integers.