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