Westonci.ca is the ultimate Q&A platform, offering detailed and reliable answers from a knowledgeable community. Join our Q&A platform to get precise answers from experts in diverse fields and enhance your understanding. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.
Sagot :
Answer:
Explanation:
class Solution {
public int search(int[] nums, int target) {
int n = nums.length;
int low = 0 , high = n - 1;
While(low < high){//Set virtual node
int mid = (low + high) / 2;
if(nums[mid] > nums[high]){
low = mid + 1;
}else{
high = mid;
}
}
int rot = low;
low = 0;
high = n - 1;
while(low <= high){
int mid = (low + high) / 2;
Int real = (mid + rot) % n;//The virtual node is mapped to the real node.
if(nums[real] == target){
return real;
}else if(nums[real] < target){
low = mid + 1;
}else{
high = mid - 1;
}
}
return -1;
}
}
Thanks for stopping by. We are committed to providing the best answers for all your questions. See you again soon. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.