Merge pull request #28 from tianshengsui/master

添加0704.二分查找Python版本
This commit is contained in:
Carl Sun
2021-05-12 18:15:16 +08:00
committed by GitHub

View File

@ -151,6 +151,22 @@ Java
Python
```python3
class Solution:
def search(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 -1
```
Go