Skip to content

Commit

Permalink
二分搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Mar 19, 2019
1 parent 2f5a1fa commit f93ba7e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 704. Binary Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def search(self, nums: List[int], target: int) -> int:
def bin_search(left, right, tar):
if left > right:
return -1
mid = (left + right) // 2
if nums[mid] < tar:
return bin_search(mid + 1, right, tar)
elif nums[mid] > tar:
return bin_search(left, mid - 1, tar)
else:
return mid
return bin_search(0, len(nums) - 1, target)

0 comments on commit f93ba7e

Please sign in to comment.