diff options
| author | mo <mokha@cisco.com> | 2017-08-08 18:08:51 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-08 18:08:51 -0600 |
| commit | 3c713353865a2be46a29d2426ea29afdeef06045 (patch) | |
| tree | c28bcfd68dd6d2908fceec172afe6c944553db97 | |
| parent | ffba056060a106aad99351927a9441e5d00009a7 (diff) | |
pass practice tests.
| -rw-r--r-- | spec/binary_trees/is_subtree_spec.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/binary_trees/is_subtree_spec.rb b/spec/binary_trees/is_subtree_spec.rb index 46d2a5c..22728dd 100644 --- a/spec/binary_trees/is_subtree_spec.rb +++ b/spec/binary_trees/is_subtree_spec.rb @@ -209,8 +209,19 @@ Guaranteed constraints: Return true if t2 is a subtree of t1, otherwise return false. DOC describe "#subtree?" do + def to_array(tree) + return [] if tree.nil? + [tree.value, to_array(tree.left), to_array(tree.right)] + end + def subtree?(t1, t2) - false + [t1&.print, t2&.print] + return true if t1.nil? && t2.nil? + return true if t1 && t2.nil? + + x = to_array(t1) + y = to_array(t2) + x.include?(y) end null = nil |
