leetcode题目
Easy档
704. Binary Search
35. Search Insert Position
2529. Maximum Count of Positive Integer and Negative Integer
278. First Bad Version
374. Guess Number Higher or Lower
3065. Minimum Operations to Exceed Threshold Value I
169. Majority Element
1351. Count Negative Numbers in a Sorted Matrix
Medium档
34. Find First and Last Position of Element in Sorted Array
658. Find K Closest Elements
229. Majority Element II
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 -1start, end = 0, len(nums)-1while start+1<end:mid = (start+end)//2if nums[mid]<target:start = midelif nums[mid]==target:end = midelse:end = mid# 找first position of targetif nums[start]==target:return startelif nums[end] == target:return endelse:return -1