dsa · easy
Search Insert Position
Non-decreasing 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.
Example
`` Input: [1,3,5,6] 5 Output: 2 ``
Constraints
0 <= nums.length <= 4*10^4 nums is sorted in non-decreasing order; all values unique 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