All problems

Binary Search

Easy · binary search

You are given a list of integers nums sorted in ascending order, with no repeated values, and an integer target. Return the index of target in nums, or -1 if it is not there.

Examples

Example 1

Input: nums = [-4, 0, 3, 8, 12], target = 8

Output: 3

nums[3] is 8.

Example 2

Input: nums = [-4, 0, 3, 8, 12], target = 5

Output: -1

5 is not in the list.

Example 3

Input: nums = [6], target = 6

Output: 0

Constraints