class Solution {
public:
int sqrt(int x) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int sta=0,end=x;
while(sta<=end)//等号不能丢
{
long long mid=(sta+end)/2;//也必须为long long
long long square=mid*mid;//可能溢出,为long long
if(square<x)
sta=mid+1;
else if(square>x)
end=mid-1;
else return mid;
}
return end;
}
};
【leetcode】Sqrt(x)
最新推荐文章于 2022-06-14 09:19:28 发布

299

被折叠的 条评论
为什么被折叠?



