Search a Rotated List
A sorted list of distinct integers was rotated at an unknown pivot (for example [0,1,2,4,5,6,7] became [4,5,6,7,0,1,2]). Return the index of target, or -1.
Requirements
- Run in time.
Examples
EXAMPLE WALKTHROUGHright half
A guided view of the published example, not a trace of your code.
INPUT
[[4,5,6,7,0,1,2],0]TASKsearch_rotated_list()
EXPECTED OUTPUT
4Start with the input values shown in this example.
Example 1 of 3
Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Explanation: right half
Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1
Explanation: absent
Input: nums = [1], target = 0
Output: -1
Explanation: single
Hint 1
At every step, one half around the middle is still sorted.
Hint 2
Check whether the target lies inside the sorted half.