```
/**
* 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->left!=NULL){
swapTree(root);
invertTree(root->left);
invertTree(root->right);
}
}
void swapTree(TreeNode *node){
TreeNode *tem=node->left;
node->left=node->right;
node->right=tem;
}
};
```

//when Running in my computer,it can get a right result.