Re: [LeetCode] 刷到面試 Grind169 C++
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
→
03/15 16:29,
2年前
, 1F
03/15 16:29, 1F
→
03/15 16:30,
2年前
, 2F
03/15 16:30, 2F
→
03/15 16:31,
2年前
, 3F
03/15 16:31, 3F
討論串 (同標題文章)
完整討論串 (本文為第 6 之 14 篇):