Binary Search
Return the zero-based index of target in a strictly increasing array, or -1 if absent. Use logarithmic time.
Example 1
nums = [-5,0,6,11]
target = 62Explanation
6 is at zero-based index 2.
Example 2
nums = [1,4]
target = 3-1Explanation
3 falls between 1 and 4 but is absent.
Example 3
nums = [9]
target = 90Explanation
The sole element equals the target at index 0.
Constraints
- 1 <= len(nums) <= 10000
- Values are distinct signed 32-bit integers
Function contract
searchArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[-5,0,6,11]6