原文题目:
https://leetcode.com/problems/invert-binary-tree/description/
AC代码:
struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution { public: TreeNode* invertTree(TreeNode* root) { if (NULL == root) { return NULL; } /*交换左右子树*/ TreeNode* temp = root->left; root->left = root->right; root->right = temp; /*递归左右子树*/ invertTree(root->left); invertTree(root->right); return root; } };