您当前的位置: 首页 > 

对方正在debug

暂无认证

  • 5浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

二叉树中的列表(循环查找)

对方正在debug 发布时间:2020-03-01 12:21:12 ,浏览量:5

题目:https://leetcode-cn.com/contest/weekly-contest-178/problems/linked-list-in-binary-tree/ 题意: 给你一棵以 root 为根的二叉树和一个 head 为第一个节点的链表。 如果在二叉树中,存在一条一直向下的路径,且每个点的数值恰好一一对应以 head 为首的链表中每个节点的值,那么请你返回 True ,否则返回 False 。 一直向下的路径的意思是:从树中某个节点开始,一直连续向下的路径。

二叉树和链表中的每个节点的值都满足 1 right); } bool isSubPath(ListNode* head, TreeNode* root) { tree.clear(); dfs(root); while(head != nullptr) { tree2.clear(); for(auto &v :tree) { if(v->val == head->val) { if(v->left != nullptr) tree2.push_back(v->left); if(v->right != nullptr) tree2.push_back(v->right); } } if(tree2.empty() && head->next != nullptr) return false; tree.swap(tree2); head = head->next; } return true; } };

关注
打赏
1664895754
查看更多评论
立即登录/注册

微信扫码登录

0.0381s