Skip to content

Binary search · ⁨二分查找⁩

English

Binary search

The array is sorted. Return the index of target, or -1 if it isn't there. Binary search halves the range each step: check the middle element, then keep looking in just the left or right half. Far faster than scanning every element.

中文

二分查找

数组是已排序的。返回 target 的下标,如果不存在就返回 -1。二分查找每一步把范围减半:检查中间元素,然后只在左半或右半继续查找。比逐个扫描快得多。

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

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