public
Created

  • Download Gist
gistfile1.ru
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
def search(arr, t)
min = 0
max = arr.count -1
mid = (max-min)/2
if arr.count == 0 || (arr.count == 1 && arr[0] != t)
return -1
elsif t <= arr[mid]
return search(arr[0..mid], t)
else
return mid + search(arr[mid..-1], t)
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.