首页 > 其他分享 >LeetCode 69. Sqrt(x)

LeetCode 69. Sqrt(x)

时间:2022-10-18 14:00:12浏览次数:72  
标签:return int Solution mid long else Sqrt 69 LeetCode

​题目​

class Solution {
public:
int mySqrt(int x) {

long long int y=x;
int l=0;
int r=(x==1?1:x/2);
while(l<=r)
{
long long int mid=(l+r)/2;
if(mid*mid<y)
{
l=mid+1;
}
else if(mid*mid >y)
{
r=mid-1;
}
else
{
return mid;
}
}

return r;

}
};



标签:return,int,Solution,mid,long,else,Sqrt,69,LeetCode
From: https://blog.51cto.com/u_15834522/5766298

相关文章