Skip to content

Instantly share code, notes, and snippets.

@joelturnbull
Created February 23, 2024 20:45
Show Gist options
  • Save joelturnbull/71a50a3ad3d3d5d719400b7039df5dce to your computer and use it in GitHub Desktop.
Save joelturnbull/71a50a3ad3d3d5d719400b7039df5dce to your computer and use it in GitHub Desktop.
1367 Linked Lists in Binary Tree
def is_sub_path(head, root)
console = []
is_sub_pathx(head,root,console)
end
def is_sub_pathx(head, root, c)
rslts = []
if root.val == head.val
if head.next
rslts << is_sub_pathx(head.next,root.left,c) if root.left
rslts << is_sub_pathx(head.next,root.right,c) if root.right
else
return true
end
else
rslts << is_sub_pathx(head,root.left,c) if root.left
rslts << is_sub_pathx(head,root.right,c) if root.right
end
return rslts.any?
end
@joelturnbull
Copy link
Author

@joelturnbull
Copy link
Author

@SoahLi I think I can get this done w/out the flattened array of rslts but I haven't troubleshot that part. Also, I had to forward execution to another version of the main, so that I could create a console to log stuff to and return lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment