镜像二叉树
1
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: void Mirror(TreeNode *pRoot) { //一个函数就够 if(pRoot==nullptr) return; if(pRoot->left==nullptr&&pRoot->right==nullptr )//左右都是空节点以及到头了 return; TreeNode *temp=pRoot->left; pRoot->left= pRoot->right; pRoot->right=temp; if(pRoot->left!=nullptr) Mirror(pRoot->left); if(pRoot->right!=nullptr) Mirror(pRoot->right); } };