@@ -0,0 +1,919 @@
+package arithmetic;%0A%0Aimport org.junit.Assert;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Created by %E6%9D%8E%E6%81%92%E5%90%8D on 2017/6/23.%0A */%0Apublic class BinarySearch %7B%0A%0A    public static int indexOf(int%5B%5D arr, int key) %7B%0A        int low = 0;%0A        int high = arr.length - 1;%0A        while (low %3C= high) %7B%0A            int mid = (low + high) %3E%3E%3E 1;//%E5%8F%96%E4%B8%AD%E9%97%B4%E7%B4%A2%E5%BC%95%0A            long midVal = arr%5Bmid%5D;%0A%0A            if (midVal %3C key)//%E5%A6%82%E6%9E%9C%E4%B8%AD%E9%97%B4%E5%80%BC%E5%B0%8F%E4%BA%8Ekey%E5%80%BC%E5%88%99key%E5%9C%A8%E9%AB%98%E4%BD%8D%0A                low = mid + 1;%0A            else if (midVal %3E key)//%E5%A6%82%E6%9E%9C%E4%B8%AD%E9%97%B4%E5%80%BC%E5%A4%A7%E4%BA%8Ekey%E5%80%BC%E5%88%99key%E5%9C%A8%E4%BD%8E%E4%BD%8D%0A                high = mid - 1;%0A            else%0A                return mid; // %E6%89%BE%E5%88%B0%EF%BC%8C%E8%BF%94%E5%9B%9E%E7%B4%A2%E5%BC%95%E4%BD%8D%E7%BD%AE%0A%0A        %7D%0A        return -1;  // %E6%B2%A1%E6%9C%89%E6%89%BE%E5%88%B0%EF%BC%8C%E8%BF%94%E5%9B%9E -1%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D arr = %7B9, 6, 7, 4, 5, 3, 2, 1%7D;%0A        //%E9%9C%80%E5%85%88%E5%B0%86%E5%BE%85%E6%90%9C%E7%B4%A2%E7%9A%84%E6%95%B0%E7%BB%84%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F%0A        Arrays.sort(arr);//%5B1, 2, 3, 4, 5, 6, 7, 9%5D%0A        Assert.assertEquals(indexOf(arr, 6), 5);%0A%0A        Assert.assertEquals(indexOf(arr, 8), -1);%0A    %7D%0A%7D%0A

add > 二分法查找