public int search (int[] nums, int target) {
        // write code here
        if (nums.length == 0) {
            return -1;
        }

        int l = 0;
        int r = nums.length;

        int mid = 0;

        while (l <= r) {

            mid = (l + r) / 2;

            if (nums[mid] < target) {
                l = mid + 1;
            } else if (nums[mid] > target){
                r = mid - 1;
            } else {
                while (mid > 0 && nums[mid] == nums[mid - 1]) {
                    mid--;
                }
                return mid;
            }
        }

        return -1;
    }