首页 > 其他 > 详细

二分查找小结

时间:2019-07-07 11:01:46      阅读:87      评论:0      收藏:0      [点我收藏+]

Templates

技术分享图片

These templates come from LeetCode.

Tips

The tip below comes from LeetCode 278. First Bad Version.

If you are setting mid = (left+right) / 2, you have to be very careful. Unless you are using a language that does not overflow such as Python, left + right could overflow. One way to fix this is to use left + (right-left)/2 instead.

If you fall into this subtle overflow bug, you are not alone. Even Jon Bentley‘s own implementation of binary search had this overflow bug and remained undetected for over twenty years.

二分查找小结

原文:https://www.cnblogs.com/shiina922/p/11143678.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!