翻转二叉树的步骤:
1.翻转根节点的左子树(递归调用当前函数)
2.翻转根节点的右子树(递归调用当前函数)
3.交换根节点的左子节点与右子节点
1 class Solution{ 2 public: 3 void exchage(TreeNode *root){ 4 TreeNode* node=root; 5 if (node!=NULL){ 6 TreeNode* temp=node->left; 7 node ->left=node->right; 8 node->right=temp; 9 }10 }11 TreeNode *invertTree(TreeNode *root){12 TreeNode*node=root13 if (root==NULL){14 return root;15 }16 invertTree(node->left)17 invertTree(node->right)18 exchange(node);19 return root;20 21 }22 };