## python实现二分查找
```python
class Solution:
#参数nums: 整数数组
#参数target: 要查找的目标数字
#返回值:目标数字的第一个位置,从0开始
def binarySearch(self, nums, target):
return self.search(nums, 0, len(nums) - 1, target)
def search(self, nums, start, end, target):
if start > end:
return -1
mid = (start + end)//2
if nums[mid] > target:
return self.search(nums, start, mid, target)
if nums[mid] == target:
return mid
if nums[mid] < target:
return self.search(nums, mid, end, target)
#主函数
if __name__ == '__main__':
my_solution = Solution()
nums = [1,2,3,4,5,6]
target = 3
targetIndex = my_solution.binarySearch(nums, target)
print("输入:nums =", nums, " ", "target =",target)
print("输出:",targetIndex)
```