You are given a sorted array of different integers and a number target. If target is in the array, return its index. If it is not, return the index where it would have to be placed to keep the array sorted.
Your solution must run in O(log n) time.
Examples
Example 1:
Input: nums = [2,4,8,10], target = 8
Output: 2
Explanation: The number 8 is at index 2.
Example 2:
Input: nums = [2,4,8,10], target = 5
Output: 2
Explanation: 5 is not in the array. It would go between 4 and 8, at index 2.
Example 3:
Input: nums = [2,4,8,10], target = 11
Output: 4
Explanation: 11 is bigger than every number, so it goes at the end, at index 4.