精華區beta Marginalman 關於我們 聯絡資訊
※ 引述《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); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.98.88 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1725690018.A.A86.html
dont: 大師 09/07 14:24
DJYOMIYAHINA: 大師 09/07 14:24
※ 編輯: argorok (36.228.98.88 臺灣), 09/07/2024 14:25:31
argorok: 刷到神智錯亂 改一下== 09/07 14:25
sustainer123: 大師 09/07 14:30