class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
lft = 0
rht = len(nums) - 1
while lft <= rht:
mid = lft + (rht - lft) // 2
if nums[mid] == target:
return mid
elif nums[mid] < target:
lft = mid + 1
elif nums[mid] > target:
rht = mid - 1
return lft
Time Complexity: O(log(n))
Space Complexity: O(1)
https://leetcode.com/problems/search-insert-position/discussion/