1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Solution: def search(self, nums, target): s = 0 e = len(nums) - 1 while (s <= e): mid = (s+e) // 2 if nums[mid] == target: return mid elif nums[mid] < target: s = mid + 1 else: e = mid - 1 return -1