Re: [閒聊] 每日leetcode

看板Marginalman作者 (死肥肥社管)時間1年前 (2024/09/07 14:20), 1年前編輯推噓3(301)
留言4則, 4人參與, 1年前最新討論串822/1548 (看更多)
※ 引述《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

09/07 14:24, 1年前 , 1F
大師
09/07 14:24, 1F

09/07 14:24, 1年前 , 2F
大師
09/07 14:24, 2F
※ 編輯: argorok (36.228.98.88 臺灣), 09/07/2024 14:25:31

09/07 14:25, 1年前 , 3F
刷到神智錯亂 改一下==
09/07 14:25, 3F

09/07 14:30, 1年前 , 4F
大師
09/07 14:30, 4F
文章代碼(AID): #1cs_2Yg6 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cs_2Yg6 (Marginalman)