示例:
輸入:
4
/ \
2 7
/ \ / \
1 3 6 9
輸出:
4
/ \
7 2
/ \ / \
9 6 3 1
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
Inver(root);
return root;
}
private:
void Inver(TreeNode* t)
{
if(t==NULL)
return;
TreeNode *tmp=t->left;
t->left=t->right;
t->right=tmp;
Inver(t->left);
Inver(t->right);
}
};