看板 Marginalman 關於我們 聯絡資訊
靠邀第一次用網頁版發文 這個是vimㄇ== 看到^Q才想到要怎麼貼上 我不太會用ㄟ 打完桌游準備要睡 又水了一題:))) 可是大家都寫得好乾淨喔 只剩我寫得這麼冗了 第一個if是不需要ㄇ?? /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: TreeNode* removeLeafNodes(TreeNode* root, int target) { if(root->left == nullptr and root->right == nullptr){ if(root->val == target){ return nullptr; } } if(root->left != nullptr){ root->left = removeLeafNodes(root->left, target); } if(root->right != nullptr){ root->right = removeLeafNodes(root->right, target); } if(root->left == nullptr and root->right == nullptr){ if(root->val == target){ return nullptr; } } return root; } }; -- https://i.imgur.com/RebxIAp.gif
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.208 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1715979306.A.5DA.html
sixB: 快中風拿回平板了 05/18 04:58
sixB: 你們回文要複製貼上都怎麼用的 05/18 04:58
sixB: 還是大家都很習慣電腦開ptt? 05/18 04:58
sixB: 第一次發文有p幣== 05/18 04:58
wu10200512: 用pttstar 05/18 09:13