```
class Solution {
void swapTwoBranches(TreeNode* root)
{
if(root!=NULL)
if(root->left!=NULL||root->right!=NULL)
{
TreeNode* originLeftNode;
originLeftNode = root->left;
root->left = root->right;
root->right = originLeftNode;
swapTwoBranches(root->left);
swapTwoBranches(root->right);
}
}
TreeNode* invertTree(TreeNode* root) {
swapTwoBranches(root);
return root;
}
```

};