还不快抢沙发

添加新评论

翻转一棵二叉树。 ``` 4 / \ 2 7 / \ / \ 1 3 6 9 ``` 转换为: ``` 4 / \ 7 2 / \ / \ 9 6 3 1 ``` 解答: ``` TreeNode* invertTree(TreeNode* root) { if (!root) { return NULL; } TreeNode* image = new TreeNode(root->val); image->left = invertTree(root->right); image->right = invertTree(root->left); return image; } ```