A sorted list of distinct version numbers was rotated at an unknown pivot (e.g. [4,5,6,7,0,1,2]). Return the index of target, or -1. Must be O(log n).
Signature
searchRotated(nums: int[], target: int) → intExample 1
nums = [4,5,6,7,0,1,2]
target = 0
output = 4
index 4
Example 2
nums = [4,5,6,7,0,1,2]
target = 3
output = -1
absent
Constraints
1 ≤ n ≤ 5000values distinct
⌘/Ctrl + Enter runs examples
Run checks the examples. Submit runs every hidden test (16, including large inputs that catch slow solutions).