java二分法查找的递归算法怎么实现
public class Solution {
public int binarySearch(int[] nums, int target) {
if (nums == null || nums.length == 0) {
return -1;
}
return helper(nums, target, 0, nums.length-1);
}
private int helper(int[] nums, int target, int start, int end) {
if (start>end) {
return -1;
}
int mid = start + (end-start)/2;
if (nums[mid] == target) {
return mid;
} if (nums[mid]
赞1
踩0