Linked List in Binary Tree LeetCode solution in C++

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0