publicclassSolution{/**
* @param nums: The integer array.
* @param target: Target to find.
* @return: The first position of target. Position starts from 0.
*/publicintbinarySearch(int[] nums,int target){// write your code hereint len = nums.length;if(len ==0){return-1;}int l =0, r = len;while(l < r){int mid = l +(r - l)/2;int num = nums[mid];if(num == target){
r = mid;}elseif(num > target){
r = mid;}else{
l = mid +1;}}if(r == len){return-1;}return nums[r]== target ? r :-1;}}
publicclassSolution{/**
* @param nums: The integer array.
* @param target: Target to find.
* @return: The first position of target. Position starts from 0.
*/publicintbinarySearch(int[] nums,int target){// write your code hereint len = nums.length;if(len ==0){return-1;}int l =0, r = len -1;while(l <= r){int mid = l +(r - l)/2;int num = nums[mid];if(num == target){
r = mid -1;}elseif(num > target){
r = mid -1;}else{
l = mid +1;}}return nums[l]== target ? l :-1;}}