Skip to content

Commit eafdc4b

Browse files
committed
relocate some files
1 parent 2f9c932 commit eafdc4b

4 files changed

+3
-1
lines changed
File renamed without changes.

Medium/SqrtX.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ public int sqrt(int x) {
1010
if(x==0) return 0;
1111
if(x==1) return 1;
1212
int left=1,right=x-1;
13-
while(left+1<right){
13+
while(left+1<right){ // 注意是left+1 !!!
1414
int mid=left+(right-left)/2;
15+
// 如果是mid*mid可以在之前定义一个midSquare这样可以不用重复计算mid*mid的值
16+
// 不能是mid*mid,应该是mid==x/mid,否则会overflow
1517
if(mid==(x/mid)) return mid;
1618
if(mid>(x/mid)) right=mid;
1719
else left=mid;

0 commit comments

Comments
 (0)