Linked List in Binary Tree LeetCode solution in C++
1class Solution {2public:3bool func(ListNode *head, TreeNode *root) {4if (!head) return true;5if (!root) return false;6if (head->val == root->val)7return func(head->next, root->left) or func(head->next, root->right);8return false;9}10bool isSubPath(ListNode *head, TreeNode *root) {11if (!root) return false;12if (func(head, root)) return true;13return isSubPath(head, root->left) or isSubPath(head, root->right);14}15};