Flashcards
Search rotated array
Flashcards do conjunto (1)
- 1Search rotated arrayclass Solution {
public int search(int[] nums, int target) {
int low = 0, high = nums.length - 1;
int x = target;
while(low <= high){
int mid = (low+high)/2 ;
if(nums[mid] == x ) return mid;
if( nums[mid] <= nums[high]){
if(x > nums[mid] && x <= nums[high]){
low = mid + 1;
}else
high = mid - 1;
}else if(nums[mid] >= nums[low]){
if(x >= nums[low] && x < nums[mid] ){
high = mid - 1;
}else
low = mid + 1;
}
}
return -1;
}
}
Informações
- Descrição
- FlashCards sobre Search rotated array, criado por Suhas S em 12-02-2018.
- Criado por
- Suhas S
- Visualizações
- 11
- Tags
- Avaliação