226. 翻转二叉树

题目链接:https://leetcode-cn.com/problems/invert-binary-tree/

执行用时:4 ms, 在所有 C++ 提交中击败了57.66%的用户
内存消耗:9.3 MB, 在所有 C++ 提交中击败了94.12%的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if (root == nullptr) return root;
TreeNode *tmp;
tmp = root->left;
root->left = root->right;
root->right = tmp;
invertTree(root->left);
invertTree(root->right);
return root;
}
};

226. 翻转二叉树
https://pisces34.github.io/2021/08/27/leetcode/226/
发布于
2021年8月27日
许可协议