leetcode 1367 Linked List in Binary Tree

isSubFrom(head,root)判断从root开始,是否存在链表中的数字。

class Solution {
public:
    bool isSubPath(ListNode* head, TreeNode* root) {
        if(!head) return true;
        if(!root) return false;
        return isSubFrom(head,root)||isSubPath(head,root->left)||isSubPath(head,root->right);//判断当前root节点是否存在链表中的数字;如果不存在,则判断从其左子树开始是否存在;如果不存在,判断从其右子树开始是否存在。
    }
    
    bool isSubFrom(ListNode* head,TreeNode* root) {
        if(!head) return true;
        if(!root||head->val!=root->val) return false;
        return isSubFrom(head->next,root->left)||isSubFrom(head->next,root->right);
    }
};
原文地址:https://www.cnblogs.com/LiuQiujie/p/12685129.html