public int search (int[] nums, int target) {
    // write code here
    int left=0;
    int right=nums.length;
    if(nums.length==0)
    {
        return -1;
    }
    boolean flag=false;
    while(left<right)
    {

        int mid=left+(right-left)/2;
        if(nums[mid]==target)
        {
            flag=true;
            right=mid;
        }
        else if(nums[mid]<target)
        {
            left=mid+1;
        }
        else if(nums[mid]>target)
        {
            right=mid;
        }
    }
    if(flag==true)
        return left;
    else
        return -1;
}

}