Explore Westonci.ca, the top Q&A platform where your questions are answered by professionals and enthusiasts alike. Get expert answers to your questions quickly and accurately from our dedicated community of professionals. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.
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;
}
}
We appreciate your time. Please revisit us for more reliable answers to any questions you may have. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca. Stay informed by coming back for more detailed answers.