标签:leetcode
class Solution {
public:
int divide(int dividend, int divisor) {
long long div = dividend,dis = divisor;
div = abs(div);
dis = abs(dis);
long long res = 0;
while(div>=dis)
{
long long temp = dis;
int i = 0;
while(div>=temp)
{
temp = temp<<1;
i++;
}
res += ((long long)1<<(i-1));
div -= (dis<<(i-1));
}
res = ((long long)dividend>0^(long long)divisor>0)?-res:res;
if(res>((1<<31)-1))
return (1<<31)-1;
return res;
}
};
标签:leetcode
原文地址:http://blog.csdn.net/majing19921103/article/details/44862875