二分查找
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
high=len(nums)-1
low=0
while high>=low:
n= ( high - low ) / 2 + low
if nums[n] == target:
return n
elif nums[n] < target:
low = n+1
else:
high = n-1
return -1
网友评论