Merge pull request #69 from tianshengsui/master

添加0035.搜索插入位置Python3版本
This commit is contained in:
Carl Sun
2021-05-13 17:42:20 +08:00
committed by GitHub

View File

@ -237,6 +237,22 @@ class Solution {
Python
```python3
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
while left <= right:
middle = (left + right) // 2
if nums[middle] < target:
left = middle + 1
elif nums[middle] > target:
right = middle - 1
else:
return middle
return right + 1
```
Go