Easy · Binary search
Search Insert Position
You are given a sorted list of distinct whole numbers and a number, target. Return its position if it is there, or the position it would be inserted at to keep the list sorted.
- Every number appears once.
- The answer can be one past the end of the list.
- Aim for O(log n): do not scan the whole list.
nums = [1, 3, 5, 6] target = 5 → 2Record your take