题解 | #二分查找-I#
二分查找-I
https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b
public int search (int[] nums, int target) { // write code here int start = 0; int end = nums.length-1; while(start<=end){ if(target == nums[(start+end)/2]){ return (start+end)/2; }else if(target > nums[(start+end)/2]){ start =((start+end)/2)+1; continue; }else if(target < nums[(start+end)/2]){ end = ((start+end)/2)-1; continue; } } return -1; } //while循环的时候 记住是 start<=end 防止漏掉数组为[1,2]的情况