二分查找
class Solution:
def search(self, nums: List[int], target: int) -> int:
//二分查找
low,high=0,len(nums)-1 //这种定义方式
while low<=high: //所有括号用冒号代替,这个地方一定要加上等于号!!!!
temp=(low+high)//2 //除法要用两个连除表示 ,这里以后要用low+(high-low)/2 防止溢出
if target==nums[temp]: //:::::
return temp
elif target>nums[temp]: //elif !!
low=temp+1
else:
high=temp-1
return -1
2.
if isBadVersion(temp-1)==False and isBadVersion(temp): //false的F要大写,与用and实现

浙公网安备 33010602011771号