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;
}
}
}
全部评论

相关推荐

04-09 09:47
门头沟学院 Java
Arbelite_:2-3k,这工资还不如去摇奶茶
点赞 评论 收藏
分享
02-17 20:43
西北大学 Java
在做测评的猫头鹰很紧张:他问你,你问deep seek
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务