You are given a sorted array of distinct integers nums and a target value.
· If target exists in the array, return its index.
· If not, return the index where target should be inserted to maintain the sorted order.
· Your algorithm must run in O(log n) time.
Input: nums = [2,4,7,10], target = 7
Output: 2
Explanation:
7 is found at index 2.
Input: nums = [2,4,7,10], target = 5
Output: 2
Explanation:
5 should be inserted at index 2 to maintain order.
Input: nums = [2,4,7,10], target = 12
Output: 4
Explanation:
2 would be placed at the end, index 4.
Accepted:
Submission: