题解 | #在旋转过的有序数组中寻找目标值# 旋转数组万能模板
在旋转过的有序数组中寻找目标值
http://www.nowcoder.com/practice/87c0e7abcbda41e7963660fa7d020995
public int search (int[] nums, int target) { // write code here int left =0,right = nums.length-1; while(left<=right){ int mid = (left+right)>>1; if(nums[mid]==target) return mid; else if(nums[left]<=nums[mid]){ if(nums[left]<=target&&target<nums[mid]) right= mid; else left = mid+1; }else { if(nums[mid]<target&&target<=nums[right]) left = mid+1; else right =mid; } } return -1; }