Binary Search (Find Target in Sorted Array)

Given a sorted array of integers and a target, determine if the target exists in the array using binary search.

Input Format

nums = sorted array of integers, target = integer

Output Format

true if target exists in nums, false otherwise

Constraints

  • 0 <= nums.length <= 10^5

Examples

Example 1:

Input:

nums = [-1,0,3,5,9,12]
target = 9

Output:

true

Explanation:

9 is present in the array.

Loading...
Binary Search (Find Target in Sorted Array)