二分查找 --递归
public static List<Integer> half(int[] arr,int left,int right,int findVal){
if (left > right){
return null;
}
int mid = (left+right)/2;
if (findVal<arr[mid]){
return half(arr,left,mid-1,findVal);
}else if (findVal>arr[mid]){
return half(arr,mid+1,right,findVal);
}else {
List<Integer> alist= new ArrayList<Integer>();
int tempIndex = mid-1;
while (tempIndex>=0 && arr[tempIndex]==findVal){
alist.add(tempIndex);
tempIndex--;
}
alist.add(mid);
tempIndex=mid+1;
while (tempIndex < arr.length && arr[tempIndex]==findVal){
alist.add(tempIndex);
tempIndex++;
}
return alist;
}
}