翻转一棵二叉树。
示例:
输入:
4
/ \
2 7
/ \ / \
1 3 6 9
输出:
4
/ \
7 2
/ \ / \
9 6 3 1
C++
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
TreeNode *r;
if(root==NULL)
return NULL;
r=root->left;
root->left=root->right;
root->right=r;
invertTree(root->left);
invertTree(root->right);
return root;
}
};