题目:用指针实现有序数组中得二分查找
code:
def twoSearch(nums, k):
begin = 0
end = len(nums)
while begin < end:
mid = (end + begin) // 2
if nums[mid] > k:
end = mid
elif nums[mid] < k:
begin = mid + 1
else:
return mid
if __name__ == "__main__":
nums = [1,3, 5, 6, 7, 8, 13, 14, 15, 17, 18, 24, 30, 43, 56]
k = 6
print(twoSearch(nums, k))