class Solution { public int[] searchRange(int[] nums, int target) { int x = left(nums, target); if (x == -1) { return new int[] { -1, -1 }; }else{ return new int[]{x,right(nums,target)}; } } public int left(int[] nums, int target) { int i = 0, j = nums.length - 1; int flag = -1; while (i <= j) { int m = (i + j) >>> 1; if (target < nums[m]) { j = m - 1; } else if (target > nums[m]) { i = m + 1; } else { flag = m; j = m - 1; } } return flag; } public int right(int[] nums, int target) { int i = 0, j = nums.length - 1; int flag = -1; while (i <= j) { int m = (i + j) >>> 1; if (target < nums[m]) { j = m - 1; } else if (target > nums[m]) { i = m + 1; } else { flag = m; i = m + 1; } } return flag; } }
标签:return,target,nums,int,34,力扣,flag,else From: https://www.cnblogs.com/gstszbc/p/18383463