```
public class Solution {
public int search(int[] nums, int target) {
if(nums==null || nums.length==0) return -1;
if(nums.length==1) return nums[0]==target?0:-1;
return binarySearch(nums, 0, nums.length-1, target);
}
public int binarySearch(int[] nums, int lo, int hi, int target){
if(lo+1>=hi) return nums[lo]==target?lo:(nums[hi]==target)?hi:-1;
int mid = lo+ (hi-lo)/2;
if(nums[mid]==target) return mid;
int left=binarySearch(nums, lo, mid-1, target);
int right=binarySearch(nums, mid+1,hi,target);
if(left>=0) return left;
if(right>=0) return right;
return -1;
}
}
```