case 1
如果结点为NULL或者左右子树都是NULL,直接返回结点指针
case 2
如果结点有左右指针,交换左右指针,然后镜像左子树,镜像右子树,返回结点指针
class Solution {
public:
TreeNode* Mirror(TreeNode* pRoot) {
if(pRoot == nullptr || (pRoot->left == nullptr && pRoot->right == nullptr)) return pRoot;
swap(pRoot->left, pRoot->right);
Mirror(pRoot->left);
Mirror(pRoot->right);
return pRoot;
}
};


京公网安备 11010502036488号