作者SuiseiLeda (彗星雷達)
看板Marginalman
標題Re: [LeetCode] 刷到面試 Grind169 C++
時間Wed Mar 15 16:23:56 2023
226. Invert Binary Tree easy題
二差樹歷遍而已
難得我會
但我runtime跟memory超爛
是要改迭代比較好嗎
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if(root == NULL) return root;
invertTree(root->left);
invertTree(root->right);
swap(root->left, root->right);
return root;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.136.220 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1678868638.A.19C.html
→ FuGuRo: 好強喔我才剛在學資料型態== 03/15 16:29
→ SuiseiLeda: 別學了 直接開刷 不會再回頭看 03/15 16:30
→ FuGuRo: 好 跟著大師走 03/15 16:31