Binary Search
nums is sorted in increasing order with no repeats. Return the index of target, or -1 if it is not in the list.
The point of the exercise is to halve the search range each step.
Example 1
nums [-1,0,3,5,9,12]
target 9
returns 4
9 is at index 4.
Example 2
nums [-1,0,3,5,9,12]
target 2
returns -1
2 is not in the list.
Constraints
0 <= len(nums) <= 40- Items of
numsare distinct and sorted.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.