二分查找算法
public class test4 {
public static void main(String[] args) {
int[] nums = { 55, 75, 68, 35, 22, 88, 56 };
int index = find(nums, 22);
System.out.println(index);
}
public static int find(int[] nums, int key) {
int start = 0;
int end = nums.length - 1;
while (start <= end) {
int medil = (start + end) / 2;
if (nums[medil] > key) {
start = medil + 1;
} else if (nums[medil] < key) {
end = medil - 1;
} else {
return medil;
}
}
return -1;
}
}