Skip to content

Commit

Permalink
Merge pull request youngyangyang04#28 from tianshengsui/master
Browse files Browse the repository at this point in the history
添加0704.二分查找Python版本
  • Loading branch information
youngyangyang04 authored May 12, 2021
2 parents 8591295 + 1f609be commit fbe43be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions problems/0704.二分查找.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fbe43be

Please sign in to comment.