LeetCode: https://leetcode.com/problems/search-in-rotated-sorted-array/
There is an integer array nums sorted in ascending order (with distinct values), and rotated. Given the array and an integer target, return the index of target or -1 if it is not found.
Example:
- Input:
nums = [4,5,6,7,0,1,2], target = 0 - Output:
4
l
4
0
5
1
6
2
mid
7
3
0
4
1
5
r
2
6
target=0
Step 1 / 5
Step 1:
Initialize l=0, r=6. Compute mid=3.
Pointers: l=0, mid=3, r=6
Focus: select @ [0, 3, 6]
target=0