Example 1
Input
nums = [1, 3, 5, 6], target = 5
Output
2
Loading CodeSprint...
/problems/search-insert-position
Given a strictly increasing integer list, return the index of a target if present. Otherwise return the index where it belongs to keep the list sorted.
Implement this function and return the result. CodeSprint supplies each test case automatically.
searchInsert(nums, target) → numberInput
nums = [1, 3, 5, 6], target = 5
Output
2
Input
nums = [1, 3, 5, 6], target = 2
Output
1
Constraints
0 <= nums.length <= 100,000 nums is sorted in strictly increasing order.