添加0035.搜索插入位置Python3版本

This commit is contained in:
Tiansheng Sui
2021-05-12 22:42:44 -07:00
committed by GitHub
parent e01b39eab2
commit a1b5896b69

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