题解 | #二分查找-II#
二分查找-II
http://www.nowcoder.com/practice/4f470d1d3b734f8aaf2afb014185b395
二分
import java.util.*;
public class Solution {
public int search (int[] nums, int target) {
int n = nums.length;
int l = 0,r = n - 1;
while(l < r){
int mid = l + r >> 1;
if(nums[mid] >= target)r = mid;
else l = mid + 1;
}
if(n == 0 || nums[l] != target)l = -1;
return l;
}
}