Loading…
Loading…
Given a sorted array of distinct integers and a target, return the index if found, or the index where it would be inserted to keep the array sorted.
Input: nums = 1 3 5 6, target = 2
Output: 1
Standard binary search — when the loop ends without finding the target, low is exactly the correct insertion point.
Line 1: the array, space-separated Line 2: target
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.