Total Accepted: 75767 Total Submissions: 314003 Difficulty: Medium
Implement int sqrt(int x)
.
Compute and return the square root of x.
class Solution {
public:
int mySqrt(int x) {
if(x<){
return INT_MIN;
}
if(x==){
return ;
}
long long int low = ;
long long int high= (long long int)x+;
while(low<high){
long long int mid = low + (high-low)/;
if(mid > x/mid){
high = mid;
}else if(mid == x/mid){
return mid;
}else{
low = mid+;
}
}
return low-;
}
};