// Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

// Your algorithm's runtime complexity must be in the order of O(log n).

// If the target is not found in the array, return [-1, -1].

// Example 1:

// Input: nums = [5,7,7,8,8,10], target = 8
// Output: [3,4]
// Example 2:

// Input: nums = [5,7,7,8,8,10], target = 6
// Output: [-1,-1]

class Solution {
    // score:100(4ms)
    // time:O(logn)
    // space:O(1)
    public int[] searchRange(int[] nums, int target) {
        int[] ret = new int[] { -1, -1 };
        if (nums.length < 1) {
            return ret;
        }
        int l = 0, r = nums.length - 1;
        int mid;
        // Search for the left one
        while (l < r) {
            mid = (l + r) / 2;
            if (nums[mid] < target) {
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        if (nums[l] != target) {
            return ret;
        }
        ret[0] = l;
        r = nums.length - 1;
        // Search for the right one
        while (l < r) {
            // Make mid biased to the right
            mid = (l + r) / 2 + 1;
            if (nums[mid] > target) {
                r = mid - 1;
            } else {
                l = mid;
            }
        }
        ret[1] = r;
        return ret;
    }
}