Looking for reliable answers? Westonci.ca is the ultimate Q&A platform where experts share their knowledge on various topics. Experience the ease of finding quick and accurate answers to your questions from professionals on our platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
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 hope our answers were helpful. Return anytime for more information and answers to any other questions you may have. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Westonci.ca is here to provide the answers you seek. Return often for more expert solutions.