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
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.