Binary search
mediumSorting and searching20 XP
nums is sorted from small to large with no repeats. Return the position of target, or -1 if it isn't there. Check the middle, then keep only the half that can contain the target.
Examples
- Input: nums = [-1, 0, 3, 5, 9, 12], target = 9Output: 4
- Input: nums = [-1, 0, 3, 5, 9, 12], target = 2Output: -1
Examples use JSON: true/false/null are True/False/None in Python.