Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (supertroller)時間2年前 (2023/02/18 11:08), 2年前編輯推噓4(401)
留言5則, 5人參與, 2年前最新討論串237/719 (看更多)
226. Invert Binary Tree 給一棵二元樹, 要把樹上的每個節點的左右子節點都交換。 Example 1: Input: root = [4, 2, 7, 1, 3, 6, 9] Output: [4, 7, 2, 9, 6, 3, 1] Explanation: https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg
Example 2: Input: root = [2, 1, 3] Output: [2, 3, 1] Explanation: https://assets.leetcode.com/uploads/2021/03/14/invert2-tree.jpg
Example 3: Input: root = [] Output: [] Explanation: 樹上沒有任何節點,直接返回空的樹 解題思路: 遞迴處理左右子節點, 然後把當前節點的左右子節點交換。 C++ code: class Solution { public: TreeNode* invertTree(TreeNode* root) { if(!root) return NULL; TreeNode *temp = root->right; root->right = invertTree(root->left); root->left = invertTree(temp); return root; } }; --- 最近作息又開始變晚了, 然後題目連續好幾天都是Easy,有點無聊。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.229.216 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1676689686.A.0EC.html

02/18 11:25, 2年前 , 1F
大師
02/18 11:25, 1F

02/18 11:25, 2年前 , 2F
這禮拜6天有3天都是我寫過的= =
02/18 11:25, 2F
刷水題大師 :000 ※ 編輯: idiont (140.113.229.216 臺灣), 02/18/2023 11:55:19

02/18 12:06, 2年前 , 3F
這題很有名Max Howell去面試google寫不出這題被刷掉
02/18 12:06, 3F
真假 我第一眼看到只覺得怎麼有那麼水的題目 :000 有修過資料結構應該都能寫得出來吧 ※ 編輯: idiont (140.113.229.216 臺灣), 02/18/2023 13:25:26

02/18 14:18, 2年前 , 4F
笑死 經典二元數反轉
02/18 14:18, 4F

02/19 00:03, 2年前 , 5F
可以打打比賽還蠻有趣的
02/19 00:03, 5F
以前大學打過ICPC 但後來也沒有在練 就沒特別去打線上賽了 ※ 編輯: idiont (140.113.229.216 臺灣), 02/19/2023 00:13:01
文章代碼(AID): #1Zy44M3i (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1Zy44M3i (Marginalman)