Commit 3c71335

mo <mokha@cisco.com>
2017-08-09 00:08:51
pass practice tests.
1 parent ffba056
Changed files (1)
spec
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