二分查找
使用条件
- 数组有序
使用流程
假设数组递增
- 取start, end, 算 center = (int)((end - start) / 2) + start 1.1. target = center 即找到 1.2. target > center, 则 start = center + 1 1.3. target < center, 则 end = center - 1
- 循环条件: start < end
优势
遍历查找时间复杂度: O(n) 二分查找时间复杂度: O(logn)
在数据量很大的时候, 性能相差很明显