Skip to content

Binary search · ⁨二分查找⁩

English

Binary search

The array is sorted and has n elements. Return the index of target, or -1 if it isn't present. Keep lo and hi bounds, check the middle each step, and discard the half that can't contain the target.

中文

二分查找

数组是已排序的,有 n 个元素。返回 target 的下标,如果不存在就返回 -1。维护 lo 和 hi 边界,每一步检查中间元素,丢弃不可能包含目标的那一半。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩