class Solution {
public:
int sqrt(int x) {
int left=1,right=x/2;
int res;
if(x<2)return x;
while(left<=right)
{
int mid=(right-left)/2+left;
if(x/mid>mid)left=mid+1,res=mid;
else if(x/mid<mid)right=mid-1;
else return mid;
}
return res;
}
};
网友评论