题解 | #二分查找-I#
二分查找-I
https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b
class Solution: def search(self , nums: List[int], target: int) -> int: # write code here if not nums: return -1 left = 0 right = len(nums) - 1 while left <= right: mid = (right + left) // 2 if nums[mid] == target: return mid elif nums[mid] > target: right = mid - 1 else: left = mid + 1 return -1