← problems
#33

Search in Rotated Sorted Array

MediumBinary Search

There is a sorted ascending array of distinct integers nums that was rotated at some pivot. Given nums and target, return the index of target, or -1 if it is not present. Run in O(log n).

Example

nums = [4, 5, 6, 7, 0, 1, 2], target = 0  => 4
nums = [4, 5, 6, 7, 0, 1, 2], target = 3  => -1
Implement
function Search(nums: int[], target: int) -> int

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…