模板一
int[] nums = {0, 0, 1, 2, 2, 5, 6}; int l = 0, r = 6, target = 0; while(l < r) { int mid = l + r >> 1; if(nums[mid] >= target) r = mid; else l = mid + 1; } return l;
//返回结果是0
模板二
int[] nums = {0, 0, 1, 2, 2, 5, 6}; int l = 0, r = 6, target = 0; while(l < r) { int mid = l + r + 1>> 1; if(nums[mid] <= target) l = mid; else r = mid - 1; } return l;
//返回结果是1