※ 引述《dont (dont)》之銘言:
: 1367. Linked List in Binary Tree
: ## 思路
preorder 遍歷整個tree, 每個node都recursion檢查一下是否有path
class Solution {
public:
bool check(ListNode* head, TreeNode* root) {
if(head == nullptr) return true;
if(root == nullptr || head->val != root->val) return false;
head = head->next;
return check(head, root->left) || check(head, root->right);
}
bool isSubPath(ListNode* head, TreeNode* root) {
if(root == nullptr) return false;
if(check(head, root)) return true;
return isSubPath(head, root->left) || isSubPath(head, root->right);
}
};