原题链接:https://leetcode-cn.com/problems/linked-list-in-binary-tree/
嵌套递归
bool isSubPath(ListNode* head, TreeNode* root) {
if(head==NULL) return true;
if(root==NULL) return false;
return isSub(head,root)||isSubPath(head,root->left)||isSubPath(head,root->right);//依次判断每个节点
}
bool isSub(ListNode * head,TreeNode* root){//判断当前节点是否在列表中
if(head==NULL) return true;
if(root==NULL) return false;
if(head->val!=root->val){
return false;
}else{
return isSub(head->next,root->left)||isSub(head->next,root->right);//如果在列表中,则判断下一个列表元素
}
}