Skip to content
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

Open
nomyfan opened this issue Nov 24, 2019 · 0 comments
Open

面试题11,中间索引计算方法可能整数溢出 #69

nomyfan opened this issue Nov 24, 2019 · 0 comments

Comments

@nomyfan
Copy link

nomyfan commented Nov 24, 2019

书上的代码:

indexMid = (index1 + index2) / 2;

如果数组很长,并且最小值在比较靠后的位置(两个index都比较大)那就有可能导致算出的indexMid不正确。一般来说不都是这样写吗?

indexMid = index1 + (index2 - index1) / 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant