在排序数组中查找元素的第一个和最后一个位置
class Solution { public int[] searchRange(int[] nums, int target) { int len = nums.length; int start = 0; int end = len - 1; int mid = 0; int temp = 0; while(start<=end){ mid = (start+end)/2; if(nums[mid]>=target){ end = mid - 1; }else{ start = mid + 1; } } temp = start; end = len - 1; while(start<=end){ mid = (start+end)/2; if(nums[mid]>target){ end = mid - 1; }else{ start = mid + 1; } } return temp>end?new int[]{-1,-1}:new int[]{temp,end}; } }