Not much to say about this other than its a simple binary search! Calculate the midpoint and check whether the target is on the larger or smaller half (only works on sorted arrays or BSTs)
classSolution:defsearch(self, nums: List[int], target:int)->int: l, r =0,len(nums)-1while l <= r: mid =(r + l)//2if target == nums[mid]:return mid
elif target > nums[mid]: l = mid +1else: r = mid -1return-1