mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
添加0704二分查找 Ruby 版本
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user