题目

要点
- Binary Search
代码
class Solution(object):def searchInsert(self, nums, target):""":type nums: List[int]:type target: int:rtype: int"""l = 0r = len(nums) - 1while(l<=r):mid = (l + r)//2if nums[mid] == target:return midelif nums[mid] < target:l = mid + 1else:r = mid - 1return l
分析
二分查找(binary search)是算法中必须掌握的基础算法之一。此题与二分法无异
