添加0704二分查找 Ruby 版本

This commit is contained in:
reoooh
2021-07-29 00:07:44 +08:00
parent 31c9f09776
commit 4fcb27c7cf

View File

@ -337,7 +337,7 @@ end
# (版本二)左闭右开区间
def search(nums, target)
left, right = 0, nums.length - 1
left, right = 0, nums.length
while left < right # 由于定义target在一个在左闭右开的区间里因此极限情况下right=left+1
middle = (left + right) / 2
if nums[middle] > target