diff options
| author | mo <mokha@cisco.com> | 2017-08-09 15:23:00 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-09 15:23:00 -0600 |
| commit | efb899eaa9f14a275471bfdf975e4a776f65ad62 (patch) | |
| tree | cae125b507927d87020f4d21a312df5d020bbf36 /spec/binary_trees | |
| parent | c72bb09e658d4f6609db81147b02e127edc9628c (diff) | |
shrink the search.
Diffstat (limited to 'spec/binary_trees')
| -rw-r--r-- | spec/binary_trees/restore_binary_tree_spec.rb | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/spec/binary_trees/restore_binary_tree_spec.rb b/spec/binary_trees/restore_binary_tree_spec.rb index 4877838..7003464 100644 --- a/spec/binary_trees/restore_binary_tree_spec.rb +++ b/spec/binary_trees/restore_binary_tree_spec.rb @@ -84,11 +84,8 @@ DOC describe "#restore_binary_tree" do $preorder_index = 0 - def search(items, start, end_range, value) - start.upto(end_range+1).each do |n| - return n if items[n] == value - end - nil + def search(items, start, end_range, target) + items[start..end_range].find_index { |x| x == target } + start end def build_tree(inorder, preorder, start_index, end_index) |
