```
public class Solution {
public int sqrt(int x) {
if (x==0)
{
return 0;
}
int begin = 1;
int end = x;
int result=0;
while (begin <= end) {
int mid = (begin+end) / 2;
if (mid <= x/mid ) {
begin = mid + 1;
result = mid;
} else {
end = mid - 1;
}
}
return result;
}
}
```

This is my java code which can pass the test cases. But if I modify the "if (mid <= x/mid )" to "if (mid*mid <= x )". There will be time limit exceeded. I don't know why. Is there any difference?