Binary Search
Easy
Searching
Array
Binary Search
Implement binary search. Given a sorted array and target, return the index or -1 if not found.
Constraints
1 ≤ nums.length ≤ 10^4
Examples
Example 1:
Input: -1 0 3 5 9 12
9
Output: 4
Example 2:
Input: -1 0 3 5 9 12
2
Output: -1
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console