Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
30:00
Java
Binary Search
easy
Topics
Companies
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
Example 1:
Input: {"nums":[-1,0,3,5,9,12],"target":9}
Output: 4
Constraints:
1≤nums.length≤104
−104<nums[i],target<104
All values in nums are unique.
nums is sorted in ascending order.
Input
arr ={"nums":[-1,0,3,5,9,12],"target":9}
Target: 9
-1
L
0
3
5
9
12
R
Variables
No variables to display
DepthFunction Call
Stack empty
0/7
Asked in these interview guides
Company guides that list this problem among their sample questions.