/**
* Definition for a binary tree node.
* 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(root==NULL)
{
return NULL;
}
TreeNode* temp=root->right= invertTree(root->right);//注意这里必须定义一个临时的存储空间,否则交换是失败的
root->left= invertTree(root->left);
root->right=root->left;
root->left=temp;
return root;
}
};
11-04