Problems

6. Search Insert Position

EasyBinary SearchMicrosoftGoogle

Given a sorted array and a target value, return its index or the index where it would be inserted.

Example 1:

Input: nums = [1,3,5,6], target = 5
Output: 2

Example 2:

Input: nums = [1,3,5,6], target = 2
Output: 1

Constraints:

  • 1 <= nums.length <= 10^4
Core code mode
● Auto-savedLine 1, column 1