题目:
别人的通过代码:
class Solution {
public:
int divide(int dividend, int divisor) {
// Note: The Solution object is instantiated only once.
long long a = abs((double)dividend);
long long b = abs((double)divisor);
long long res = 0;
while (a >= b)
{
long long c = b;
for (int i = 0; a >= c; i++, c <<= 1) //除数不断地*2 直到大于被除数
{
a -= c; //减去除数
res += 1 << i; //除数*2多少次 结果就要增加多少次
}
}
return ((dividend ^ divisor) >> 31) ? (-res) : (res);
}
};