classSolution{publicintsearch(int[] nums,int target){int len = nums.length;int i = len /2;int result =-1;if(target == nums[i])return i;elseif(target > nums[i]&& i != len -1){int[] temp =newint[len - i -1];System.arraycopy(nums,i+1,temp,0,len - i -1);
result =search(temp,target);if(result !=-1) result += i+1;}elseif(target < nums[i]&& i !=0){int[] temp =newint[i];System.arraycopy(nums,0,temp,0,i);
result =search(temp,target);}return result;}}
算法递归核心思想LeetCode给的解答是利用双指针进行解题,感觉也不是太二分,我选择二分到底,用的递归。代码class Solution { public int search(int[] nums, int target) { int len = nums.length; int i = len / 2; int result = -1; if(target == nums[i]) return .