← All problems
Binary Search
EasyBinary Search
Given a sorted (ascending) array of integers and a target, return its index, or -1 if not present. Must be O(log n).
Examples
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Input: nums = [-1,0,3,5,9,12], target = 2
Output: -1
Hints
Solution
Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 5 test cases.