class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
self.idx = 0
self.divide(nums, target, 0, len(nums) - 1)
return self.idx
def divide(self, nums, target, left, right):
if left > right:
self.idx = left
return right
mid = (left + right) // 2
if nums[mid] < target:
self.divide(nums, target, mid + 1, right)
elif nums[mid] > target:
self.divide(nums, target, left, mid - 1)
elif nums[mid] == target:
self.idx = mid
return mid