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

防止(p+r)的和超过int类型最大值 #269

Open
calmpeng opened this issue Mar 13, 2019 · 1 comment
Open

防止(p+r)的和超过int类型最大值 #269

calmpeng opened this issue Mar 13, 2019 · 1 comment

Comments

@calmpeng
Copy link

 // 取p到r之间的中间位置q,防止(p+r)的和超过int类型最大值
    int q = p + (r - p)/2;

这也太牛逼了吧,这都想的到!!

@hjpcs
Copy link

hjpcs commented Jun 11, 2019

看到二分查找那一节,/2还可以优化成位运算>>1

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

2 participants