33. Search in Rotated Sorted Arr
作者:
夜皇雪 | 来源:发表于
2016-12-15 13:40 被阅读0次public class Solution {
public int search(int[] nums, int target) {
int start=0,end=nums.length-1;
while(start<end){
int mid=(end-start)/2+start;
if(target==nums[mid]) return mid;
if(nums[mid]>nums[end]){
if(target<nums[mid]&&target>=nums[start]) end=mid-1;
else start=mid+1;
}else{
if(target>nums[mid]&&target<=nums[end]) start=mid+1;
else end=mid-1;
}
}
return nums[start]==target?start:-1;
}
}
本文标题:33. Search in Rotated Sorted Arr
本文链接:https://www.haomeiwen.com/subject/zaxgmttx.html
网友评论