class Solution {
public:
int divide(int dividend, int divisor) {
long long int ret=0;
long long int cpEnd=dividend>=0?dividend:-(long long int)dividend;
long long int cpOr=divisor>-0?divisor:-(long long int)divisor;
if(cpOr==0)
return INT_MAX;
while(cpEnd>=cpOr)
{
long long tmp=cpOr;
int i=0;
while(cpEnd>=tmp)
{
cpEnd-=tmp;
ret+=1<
>31 )
ret=-ret;
if (ret > INT_MAX || ret < INT_MIN)
return INT_MAX;
else
return ret;
}
};
每次除数翻倍,翻倍超过了,有从头开始