https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/

class Solution {
    public int[] searchRange(int[] nums, int target) {
        int left = 0,right = nums.length - 1;
        while(left <= right){
            int mid = left + (right - left)/2;
            if(nums[mid] < target){
                left = mid +1;
            }else if(nums[mid] > target){
                right = mid - 1;
            }else if(nums[mid] == target){
                right = mid - 1;
            }
        }
        int left1 = left;

        left = 0;
        right = nums.length - 1;
        while(left <= right){
            int mid = left + (right - left)/2;
            if(nums[mid] < target){
                left = mid +1;
            }else if(nums[mid] > target){
                right = mid - 1;
            }else if(nums[mid] == target){
                left = mid + 1;
            }
        }
        int right1 = right;

        if(left1 >= nums.length || right1 < 0){
            return new int[]{-1,-1};
        }

        return new int[]{left1,right1};
    }
}