Created
February 23, 2024 20:45
-
-
Save joelturnbull/71a50a3ad3d3d5d719400b7039df5dce to your computer and use it in GitHub Desktop.
1367 Linked Lists in Binary Tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
@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
@SoahLi