Given a binary tree root and a&nbsp;linked list with&nbsp;head&nbsp;as the first node.&nbsp;

Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree&nbsp;otherwise return False.

In this context downward path means a path that starts at some node and goes downwards.

&nbsp;
Example 1:



Input: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
Output: true
Explanation: Nodes in blue form a subpath in the binary Tree.  


Example 2:



Input: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
Output: true


Example 3:

Input: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
Output: false
Explanation: There is no path in the binary tree that contains all the elements of the linked list from head.


&nbsp;
Constraints:


	The number of nodes in the tree will be in the range [1, 2500].
	The number of nodes in the list will be in the range [1, 100].
	1 &lt;= Node.val&nbsp;&lt;= 100&nbsp;for each node in the linked list and binary tree.


class Solution(object):
    def isSubPath(self, head, root):
        if not root:
            return False
        if self.issame(head, root):
            return True
        return self.isSubPath(head, root.left) or self.isSubPath(head, root.right)
    def issame(self, head, root):
        if not head:
            return True
        if not root:
            return False
        if head.val != root.val:
            return False
        return self.issame(head.next, root.left) or self.issame(head.next, root.right)
class Solution {
    public boolean isSubPath(ListNode head, TreeNode root) {
        if(root == null) return false;
        if(issame(head, root)) return true;
        return isSubPath(head, root.left) || isSubPath(head, root.right);
    }
    private boolean issame(ListNode head, TreeNode root) {
        if(head == null) return true;
        if(root == null) return false;
        if(head.val != root.val) return false;
        return issame(head.next, root.left) || issame(head.next, root.right);
    }
}
class Solution {
public:
    bool func(ListNode *head,TreeNode *root){
        if(!head) return true;
        if(!root) return false;
        if(head->val == root->val) return func(head->next,root->left) or func(head->next,root->right);
        return false;
    }
    bool isSubPath(ListNode* head, TreeNode* root) {
        if(!root) return false;
        if(func(head,root)) return true;
        return isSubPath(head,root->left) or isSubPath(head,root->right); 
    }
};
var isSubPath = function(head, root) {
    if(!root)    return false
    if(issame(head, root))  return true
    return isSubPath(head, root.left) || isSubPath(head, root.right)
};

function issame(head, root){
    if(!head)   return true
    if(!root)   return false
    if(head.val != root.val)    return false
    return issame(head.next, root.left) || issame(head.next, root.right)
};
Linked List in Binary Tree