algos_and_structures/neetcode/arrays/binary_search
2025-02-19 23:32:54 +03:00
..
README.md Add solution for neetcode: binary search 2025-02-19 23:32:54 +03:00
solution.py Add solution for neetcode: binary search 2025-02-19 23:32:54 +03:00

Binary Search You are given an array of distinct integers nums, sorted in ascending order, and an integer target.

Implement a function to search for target within nums. If it exists, then return its index, otherwise, return -1.

Your solution must run in O(logn) time.

Example 1:

Input: nums = [-1,0,2,4,6,8], target = 4

Output: 3 Example 2:

Input: nums = [-1,0,2,4,6,8], target = 3

Output: -1 Constraints:

1 <= nums.length <= 10000. -10000 < nums[i], target < 10000