You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
二分查找法。利用两个指针 left 和 right,分别指向数组首尾位置。每次用 left 和 right 中间位置上的元素值与目标值做比较,如果等于目标值,则返回当前位置。如果小于目标值,则更新 left 位置为 mid + 1,继续查找。如果大于目标值,则更新 right 位置为 mid - 1,继续查找。直到查找到目标值,或者 left > right 值时停止查找。然后返回 left 所在位置,即是代插入数组的位置。
0 commit comments