You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
target: index of the element if found,
or the index of the greater element.
if there is no greater element, index = len
classSolution:
defsearchInsert(self, nums: List[int], target: int) ->int:
left, right=0, len(nums) -1temp_index=Nonewhile(left<=right):
mid=left+ (right-left) //2ifnums[mid] ==target:
returnmidelifnums[mid] >target:
temp_index=midright=mid-1else:
left=mid+1# or dont use the temp_index and just return left.iftemp_index==None:
temp_index=len(nums)
returntemp_index