```
TreeNode* invertTree(TreeNode* root) {
TreeNode *temp;
if(root==NULL||(root->left==NULL && root->right==NULL))
return root;
temp= root->left;
root->left=root->right;
root->right=temp;
invertTree(root->left);
invertTree(root->right);
return root;
}
```