static int x=[](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
class Solution {
public:
int divide(int dividend, int divisor) {
if(dividend == INT_MIN && divisor == -1) return INT_MAX;
long long a = abs((long long)dividend);
long long b = abs((long long)divisor);
int num = 0;
long long sum;
while(b <= a){
sum = b;
int count = 1;
while(sum + sum <= a){
count += count;
sum += sum;
}
a -= sum;
num += count;
}
if ((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0))
num = -num;
return num;
}
};
LetCode 29. 两数相除
最新推荐文章于 2024-05-13 15:39:44 发布