dsa · easy
Search Insert Position
GreyOrangeArrayBinary SearchFoundation
Sorted distinct nums. Return the index of target, or where it **would** be inserted.
Arguments
nums— the input array of integerstarget— the value you are searching for or summing to
**Example:** [1,3,5,6], target=5 → 2. target=2 → 1.
Constraints
0 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,3,5,6] 5 Expected: 2
Example 2
Input: [1,3,5,6] 2 Expected: 1