教学

https://leetcode-cn.com/problems/binary-search/solution/li-qing-er-fen-cha-zhao-by-hello1100101/arrow-up-right

左闭右闭

JDK里的数组二分查找就是用的这种,循环终止条件是 left>right

//JDK里的代码 private static int binarySearch0(int[] a, int fromIndex, int toIndex, int key) { int low = fromIndex; int high = toIndex - 1;//因为是闭区间,而toIndex是不在区间内的,所以需要-1

左开右闭

左闭右开

左开右开

Binary Search in doubles:

Last updated