leetcode每日一题——69
public static int  mySqrt(int  x){
if(x<=0)return&nbsp;0;
int&nbsp;low=1,high=x;
while&nbsp;(low<=high)&nbsp;{
long&nbsp;mid=(high-low)/2+low;
if&nbsp;(mid*mid==x)&nbsp;{
return&nbsp;(int)mid;
}else&nbsp;if(mid*mid<x)&nbsp;{
low=(int)mid+1;
}else&nbsp;{
high=(int)mid-1;
}
}
if&nbsp;(high*high<x)&nbsp;{
return&nbsp;(int)high;
}else&nbsp;{
return&nbsp;(int)low;
}
}
}
全部评论

相关推荐

从明天开始狠狠卷JV...:叽里咕噜一大堆,不就是字典序,sort一下就搞定了。
投递京东等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务