-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
面试题11,中间索引计算方法可能整数溢出 #69
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
书上的代码:
indexMid = (index1 + index2) / 2;
如果数组很长,并且最小值在比较靠后的位置(两个index都比较大)那就有可能导致算出的indexMid不正确。一般来说不都是这样写吗?
indexMid = index1 + (index2 - index1) / 2;
The text was updated successfully, but these errors were encountered: