leetcode题目
Easy档
2529. Maximum Count of Positive Integer and Negative Integer
374. Guess Number Higher or Lower
3065. Minimum Operations to Exceed Threshold Value I
1351. Count Negative Numbers in a Sorted Matrix
Medium档
34. Find First and Last Position of Element in Sorted Array
2780. Minimum Index of a Valid Split
915. Partition Array into Disjoint Intervals
模版
def binary_search_function(self, nums, target):
#当报错的时候
#就在开头把一些case特殊写出来
if nums is None:
return -1
start, end = 0, len(nums)-1
while start+1<end:
mid = (start+end)//2
if nums[mid]<target:
start = mid
elif nums[mid]==target:
end = mid
else:
end = mid
# 找first position of target
if nums[start]==target:
return start
elif nums[end] == target:
return end
else:
return -1