自己:https://sleepymonster.cn/
仓库:https://github.com/hengyi666
class Solution: def SearchInsert(self, nums: list, target: int) -> int: if target <= nums[0]: return 0 if target >= nums[-1]: return len(nums) i, j = 0, len(nums) - 1 while i < j: mid = (i+j)//2 if target <= nums[mid]: j = mid else: i = mid + 1 return j nums = [1,3,5,6] target = 2 test = Solution().SearchInsert(nums,target) print(test)
一起进步,若有帮助,点个赞吧QAQ