35. Search Insert Position
Intuition
Since the array is sorted, we can leverage binary search to find the target efficiently in O(log n) time.
If the
target
exists in the array, binary search will locate and return the index.If not found, the correct insert position for the
target
is exactly where theleft
pointer ends up — this is where the value would maintain the sorted order.
Complexity
Space Complexity
Time Complexity
Code
Last updated