35 Search Insert Position
1. Question
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Example 1:
Example 2:
Example 3:
Example 4:
2. Implementation
思路: 这题相当于找到一个数x >= target, 属于二分法找x左边界的问题
(1) Binary Search
3. Time & Space Complexity
Binary Search:时间复杂度O(logn),n是nums的长度, 空间复杂度O(1)
Last updated